Android TableLayout:拉伸一列,两列宽度相等
我需要像这样的东西。但是,两个相等列的内容经常变化,因此有时第一列的内容会大于另一列,反之亦然。我的第一个想法是使用TableLayout和Android TableLayout:拉伸一列,两列宽度相等,android,android-constraintlayout,tablelayout,android-tablelayout,Android,Android Constraintlayout,Tablelayout,Android Tablelayout,我需要像这样的东西。但是,两个相等列的内容经常变化,因此有时第一列的内容会大于另一列,反之亦然。我的第一个想法是使用TableLayout和android:layou-weight,但这没有多大帮助,因为我将android:layout-weight=“1”和android:layou-weight=“2”设置为中间的布局 <TableRow android:id="@+id/firstRow" android:layout_width="fill_parent"
android:layou-weight
,但这没有多大帮助,因为我将android:layout-weight=“1”
和android:layou-weight=“2”
设置为中间的布局
<TableRow
android:id="@+id/firstRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/0"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="0" />
<TextView
android:id="@+id/1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center"
android:text="1" />
<TextView
android:id="@+id/2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="2" />
</TableRow>
有没有一种方法可以通过使用布局或编程来实现这一点?您可以使用
app:layout\u constraint\u horizontal\u weight
属性对水平链使用contracintlayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/1"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/2"
app:layout_constraintHorizontal_weight="2.5"/>
<TextView
android:id="@+id/2"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintRight_toRightOf="@+id/3"
app:layout_constraintRight_toLeftOf="@+id/1"
app:layout_constraintHorizontal_weight="5"/>
<TextView
android:id="@+id/3"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintLeft_toRightOf="@+id/2"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_weight="2.5"/>
</android.support.constraint.ConstraintLayout>
谢谢您的回答。我想我还不够具体。左右文本视图应具有灵活的宽度,这是两者所需的最大宽度<代码>| abcde |------中间--| 2 |