【发布时间】:2016-10-23 16:09:38
【问题描述】:
我正在使用一个表格布局,其中每行都有多个复选框,并且正在使用自定义适配器。这些列确实在屏幕上均匀扩展。在父布局上,我还有一系列“选中/取消选中所有”类型的复选框,它们与 listview 复选框完美对齐。我的问题是我无法让复选框的列标题与列对齐。他们有一种蠕动,要么太多,要么太少,更不用说同时在手机和平板设备上工作了。我怀疑这个问题可能是由与最左边的复选框相关联的文本引起的,只有那些与它们相关联的文本。
这是用于选中/取消选中所有复选框的 xml,并且排列良好。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_blue"
android:orientation="horizontal">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/checkBox1"
android:layout_height="match_parent"
android:layout_weight="1"
android:width="60dp"
android:background="@color/light_blue"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Ck all"
android:textSize="15dp"
android:textStyle="bold" />
<CheckBox
android:id="@+id/checkBoxI"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/light_blue"
android:focusable="false"
android:focusableInTouchMode="false" />
<CheckBox
android:id="@+id/checkBoxII"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/light_blue"
android:focusable="false"
android:focusableInTouchMode="false" />
等等
这是用于列标题,不对齐。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_blue"
android:orientation="horizontal">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_height="match_parent"
android:layout_weight="1"
android:width="60dp"
android:gravity="center"
android:background="@color/light_blue"/>
<TextView
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/light_blue"
android:gravity="center"
android:text="I"/>
<TextView
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1"
android:background="@color/light_blue"
android:text="I"/>
等
这是又一次不排队的尝试。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_blue"
android:orientation="horizontal">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_height="match_parent"
android:width="60dp"
android:layout_weight="1"
android:text=""
android:gravity="center"
android:background="@color/light_blue"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:id="@+id/keycode"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1"
android:background="@color/light_blue"
android:text="I"
android:textStyle="bold" />
<TextView
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1"
android:background="@color/light_blue"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="II"
android:textStyle="bold" />
等等
我尝试了许多不同的文本对齐组合,甚至尝试强制列宽,这当然不能跨设备工作。我已经花了一整天的时间,仍然没有任何线索。任何帮助表示赞赏。
【问题讨论】:
标签: android listview checkbox tablelayout