我有一个水平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>

发布于 2015-03-08 15:58:27
这可以通过将android:layout_width="0dp"定义为所有textView来完成,您已经在做什么,但是在给weight时也可以设置weight。
编辑:
如果您不想垂直增长您的textView,而不是将android:singleLine="true"属性添加到布局的每个textView中。
若要删除右侧不必要的空白,请从android:layout_weight="1"中删除<space... />属性
所以会是,
<Space
android:layout_width="20dp"
android:layout_height="20dp" />https://stackoverflow.com/questions/28928490
复制相似问题