TextView随用户类型的增长而增长

时间:2015-03-08 15:54:15

标签: android

我的横向LinearLayout有几个TextViews。当用户在结果视图中键入一些数字时,它会扩展,而其他TextViews会变小。我希望所有TextViews具有固定的宽度,并在内容太大时隐藏第一个数字。我试用了ScrollViewsetMovementMethod(new ScrollingMovementMethod())或TableLayout周围的结果视图而没有运气。 SO question

    <LinearLayout
    android:id="@+id/assignment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="5"
    style="@style/Formula">

    <TextView
        android:id="@+id/operandFirst"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="50"
        style="@style/FormulaValue" />

    <TextView
        android:id="@+id/operator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:text="+"
        style="@style/FormulaOperator" />

    <TextView
        android:id="@+id/operandSecond"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="51"
        style="@style/FormulaValue" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:text="="
        style="@style/FormulaEqualSign" />

    <TextView
        android:id="@+id/result"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="101"
        style="@style/FormulaValue" />

    <Space
        android:layout_weight="1"
        android:layout_width="20dp"
        android:layout_height="20dp" />
</LinearLayout>

Updated image

1 个答案:

答案 0 :(得分:1)

可以通过将weight定义为所有textView来完成,您已经在做什么,但在您提供android:layout_width="0dp"时也设置 weight }。

修改

如果您不希望垂直增长textView而不是将android:singleLine="true"属性添加到布局的每个textView

要删除右端不必要的空白区域,请从android:layout_weight="1"

中删除<space... />属性

所以它会是,

<Space
    android:layout_width="20dp"
    android:layout_height="20dp" />