如图所示,我正在尝试填充左侧短语以匹配右侧长文本。 rihtsite上的长文本将动态变化,因此它不会是静态的。
这是我的代码:
<TableLayout
android:id="@+id/table"
android:layout_margin="10dp"
android:layout_below="@id/avatar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:text="short text"
android:gravity="center"
android:stretchColumns="1"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="5dp"
android:background="@drawable/xml_cell_shape"/>
<TextView android:text="long text is long really really long this is not a lie"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_weight="3"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="5dp"
android:background="@drawable/xml_cell_shape"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:text="short text"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="5dp"
android:background="@drawable/xml_cell_shape"/>
<TextView android:text="medium text not long nor short"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_weight="3"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="5dp"
android:background="@drawable/xml_cell_shape"/>
</TableRow>
</TableLayout>
答案 0 :(得分:0)
将TextViews包装在LinearRayout中的TableRow中。喜欢这个
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4"
android:orientation="horizontal">
<TextView
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/xml_cell_shape"
android:gravity="center"
android:padding="5dp"
android:text="short text"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="@drawable/xml_cell_shape"
android:padding="5dp"
android:gravity="center"
android:text="long text is long really really long this is not a lie"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>
</TableRow>