Android 无法使两个视图相等地占据屏幕
我使用以下代码创建一个包含文本视图和微调器的表布局Android 无法使两个视图相等地占据屏幕,android,android-tablelayout,Android,Android Tablelayout,我使用以下代码创建一个包含文本视图和微调器的表布局 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1"> <TableRow> <
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:id="@+id/lblListHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:text="Form"
android:singleLine="true"
android:textColor="#000" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown"
android:entries="@array/action"/>
</TableRow>
</TableLayout>
问题是文本视图和微调器的宽度不相等。当文本视图的大小较大时,微调器的大小变小。我怎样才能解决这个问题 将两者的
宽度
更改为零,而不是包装内容
android:layout_width="0dp"
当您同时使用weight
和width
时,width
属性将覆盖weight尝试以下操作-
<TableRow>
<TextView
android:id="@+id/lblListHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:text="Form"
android:textColor="#000" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown" />
</TableRow>
尝试使用重量属性和总重量