首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TextView以用户类型的形式增长

TextView以用户类型的形式增长
EN

Stack Overflow用户
提问于 2015-03-08 15:54:15
回答 1查看 41关注 0票数 0

我有一个水平LinearLayout和几个TextViews。当用户将一些数字输入结果视图时,它会展开,而其他TextViews则会变得越来越小。我希望所有的TextViews都有固定的宽度,当内容太大时隐藏第一个数字。我试验了周围的结果视图与ScrollViewsetMovementMethod(new ScrollingMovementMethod())或TableLayout没有运气。SO question

代码语言:javascript
复制
    <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>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-08 15:58:27

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

编辑:

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

若要删除右侧不必要的空白,请从android:layout_weight="1"中删除<space... />属性

所以会是,

代码语言:javascript
复制
<Space
    android:layout_width="20dp"
    android:layout_height="20dp" />
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28928490

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档