我已成功使用TableRow和一些TextView创建了一个TableLayout。像这样:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="A"
android:padding="3dip" />
<TextView
android:text="B"
android:gravity="right"
android:padding="3dip" />
</TableRow>
</TableLayout>
但是,当我使用自定义视图的表行创建一个TableLayout时,它只显示最后一个CustomView:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1">
<TableRow>
<MyFirstView
android:id="@+id/MyFirstView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#fff400" />
<MySecondView
android:id="@+id/MySecondView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#0045ff" />
</TableRow>
</TableLayout>
该视图在LinarLayout中工作正常,有什么东西我缺少?
所以我们可以做到50%的百分比:
<TableRow>
<MyFirstView
android:id="@+id/MyFirstView"
android:layout_width="0dp"
android:layout_weight=".50"
android:layout_height="match_parent"
android:background="#fff400" />
<MySecondView
android:id="@+id/MySecondView"
android:layout_width="0dp"
android:layout_weight=".50"
android:layout_height="match_parent"
android:background="#0045ff" />
</TableRow>
祝好运 )