【问题标题】:checkbox'ed list on each tab每个选项卡上的复选框列表
【发布时间】:2012-02-25 19:17:58
【问题描述】:

我是这个社区的新手,也是安卓开发的新手。 为了我的学习,我需要做一个(是/否)问卷,分为3组,有些问题很长,所以我想把一部分做成大文本,下面另一部分做成小文本。

我从 dev.and.com 上的教程中制作了一个 TabLayout,目前我还有一个 LinearLayout 来回答我的问题

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >

    <LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="2dp">

    <TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/text_large"
    android:textSize="16sp">
    </TextView>
    <TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/text_small"
    android:textSize="12sp">
    </TextView>
    </LinearLayout>
    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="2dp"
    android:gravity="right">
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/checkBxc">

    </CheckBox>
    </LinearLayout>
    </LinearLayout>

所有组都一样。

tabLayout 的代码类似于here

而 AgroupActivity 现在只显示一行文本(用于测试目的)。

如何使我的布局看起来像我拥有的​​每个选项卡中的列表?或者也许还有其他一些可能性?据我了解,一个简单的 ListView 的标签中不能有任何东西(在我的例子中是复选框)?

【问题讨论】:

    标签: android listview android-layout


    【解决方案1】:

    您可以使用 ListView 在每个选项卡中显示类似于列表的布局。 对于每个选项卡内容,您为每个选项卡使用一个 ListView:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <ListView android:id="@+id/android:list"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"/>
    </LinearLayout>
    

    ListView 中每一行的自定义行(your_custom_row.xml):

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          >
          <TableRow
             android:gravity="left"
             >
             <TextView
                 android:id="@+id/row_textview1"
                 android:textSize="25sp"
                 android:textStyle="bold"
                 android:layout_width="200dp"
                 android:layout_height="wrap_content"
                 android:lines="1"/>
             <TextView
                 android:id="@+id/row_textview2"
                 android:textSize="16sp"     
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:gravity="right"
                 android:paddingRight="10dp"
                 android:lines="1"/>
          </TableRow>
       </TableLayout>
    

    并使用 Adapter 将数据绑定到您的 ListView。

    【讨论】:

    • 但问题是我需要一个复选框旁边的问题,但listview只能存储一行文本,不是吗?
    • 可以在ListView中存储TextView、ImageView、Checkbox...。我给了你一个自定义行的例子(它使用 TableLayout 来显示一行)
    • 将你的list_row设置为水平布局,你可以让项目彼此相邻。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多