我的横向LinearLayout
有几个TextViews
。当用户在结果视图中键入一些数字时,它会扩展,而其他TextViews
会变小。我希望所有TextViews
具有固定的宽度,并在内容太大时隐藏第一个数字。我试用了ScrollView
或setMovementMethod(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>
答案 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" />