我想知道如何TextView在几行中显示其内容而不用硬编码XML中的宽度.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:text="Long multiline text"/>
<TextView
android:textColor="@color/text_color"
android:layout_width="130dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
任何想法都欢迎.
编辑:我的问题是,当文本超过设置的宽度(因为它到达屏幕的末尾)时,文本的一部分不会显示.我希望文本分为两行
nha*_*man 18
虽然我无法重现未包装问题,但您可以通过weight在第一个上使用a来解决定位问题TextView.使用以下XML在Eclipse中的图形布局视图中提供预期输出:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:singleLine="false"
android:text="Long multiline text"/>
<TextView
android:textColor="@color/text_color"
android:layout_width="130dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27529 次 |
| 最近记录: |