【问题标题】:Aligning columns headings on custom listview checkboxes对齐自定义列表视图复选框上的列标题
【发布时间】: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


    【解决方案1】:

    好吧,这是我的愚蠢。我忘记了在剪切和粘贴时我在表格行周围留下了 LinearLayouts。删除那些 Linearlayouts 后,事情按预期排列。我确实必须给第一列一个 textsize 参数,否则与最左边的复选框相关联的文本的可变宽度会弄乱其余列的对齐方式。我只需要使 textsize 比该列中的任何文本都大。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-13
      • 2012-12-15
      • 2011-07-23
      • 2011-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多