0

我有总重量为 10 的水平布局。我想在上面放一些不同宽度的内容。我希望我的内容看起来像它的宽度的下一个比例: 3:5:1:1 即像一个包含 30%、50%、10%、10% 列的表格 如何组织这个?我现在有:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:baselineAligned="true"
    android:clipChildren="false"
    android:orientation="horizontal"
    android:useLargestChild="true"
    android:weightSum="10" >

以及具有不同权重的 TextView,如下所示:

<TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="top"
        android:layout_weight="3"
        android:padding="2dp"
        android:text="TextView 1"
        android:textAppearance="?android:attr/textAppearanceMedium" />

但它没有用。视图位于屏幕外。如果我将 match_parent 更改为 wrap_content 它看起来不错,而我没有在其上放置大文本,那么 TextView 会长大。我不想要它,我只想显示那部分文本,它将以当前的 30、50 或其他 % 换行。

4

2 回答 2

2

你设置android:layout_width="match_parent"android:layout_width="0dp"

于 2012-05-12T13:07:21.377 回答
0

我在容器中的限制文本中找到了解决方案

android:maxEms="<Wieght of this TextView>"

似乎工作正常。但我不确定它是否正确。

于 2012-05-12T13:39:04.513 回答