Android 如何在列表视图中同时使用复选框和文本视图?
我将在列表视图中使用Android 如何在列表视图中同时使用复选框和文本视图?,android,listview,checkbox,Android,Listview,Checkbox,我将在列表视图中使用复选框和文本视图。我使用此xml代码来对齐ListView项: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <L
复选框
和文本视图
。我使用此xml代码来对齐ListView
项:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/textView_Item_Listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="gfhfgh"
android:textSize="25sp" />
</LinearLayout>
我希望将
TextView
向右对齐,将复选框
向左对齐。像这样将TextView添加到线性布局中
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<CheckBox
android:id="@+id/checkBox1"
android:weight="0.5"
android:layout_width="0dip"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView_Item_Listview"
android:weight="0.5"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="gfhfgh"
android:textSize="25sp" />
</LinearLayout>
像这样将文本视图添加到线性布局
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<CheckBox
android:id="@+id/checkBox1"
android:weight="0.5"
android:layout_width="0dip"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView_Item_Listview"
android:weight="0.5"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="gfhfgh"
android:textSize="25sp" />
</LinearLayout>
您不需要如此复杂的布局。复选框提供您需要的所有元素。您可以使用以下选项:
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="someText"
android:button="@null"
android:drawableLeft="@drawable/someDrawable"/>
您不需要如此复杂的布局。复选框提供您需要的所有元素。您可以使用以下选项:
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="someText"
android:button="@null"
android:drawableLeft="@drawable/someDrawable"/>
您可以使用
RelativeLayout
,例如
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alignParentLeft="true">
<TextView
android:id="@+id/textView_Item_Listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:alignParentRight="true"
android:text="gfhfgh"
android:textSize="25sp" />
</RelativeLayout
例如,您可以使用RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alignParentLeft="true">
<TextView
android:id="@+id/textView_Item_Listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:alignParentRight="true"
android:text="gfhfgh"
android:textSize="25sp" />
</RelativeLayout
试试这个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/textView_Item_Listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="gfhfgh"
android:textSize="25sp" />
</LinearLayout>
或
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="gfhfgh" />
</LinearLayout>
您可以将文本设置为复选框
,而不使用其他文本视图
试试这个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/textView_Item_Listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="gfhfgh"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:id="@+id/textView_Item_Listview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="gfhfgh"
android:layout_weight="4"
android:textSize="25sp" />
</LinearLayout>
或
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="gfhfgh" />
</LinearLayout>
您可以将文本设置为复选框
,而不使用其他文本视图
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="5" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:id="@+id/textView_Item_Listview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="gfhfgh"
android:layout_weight="4"
android:textSize="25sp" />
</LinearLayout>
为什么您甚至需要文本视图
CheckBox
是TextView
的扩展,它本身支持android:text
。由于我们讨论的是列表视图
,您可能还想签出。我想使用复选框来选择和删除列表视图项目您说得对。我现在无法在列表视图中触摸文本视图为什么您甚至需要TextView
CheckBox
是TextView
的扩展,它本身支持android:text
。由于我们讨论的是列表视图
,您可能还想签出。我想使用复选框来选择和删除列表视图项目您说得对。我现在不能在列表视图中触摸文本视图谢谢。我使用它并将(android:gravity=“right”)添加到文本视图代码中。它解决了Draks:我现在不能触摸文本视图。我可以触摸复选框并选中它,但Onclicklistener现在不工作使用onCheckedchangeListener
为您的复选框我为listview编写了一个McClickListener事件,表示现在不工作。我可以触摸复选框并选中它谢谢您。我使用它并添加(android:gravity=“right”)我现在不能触摸文本视图。我可以触摸复选框并选中它,但Onclicklistener现在不工作为您的复选框使用onCheckedchangeListener
,我为listview编写了一个McClickListener事件,表示现在不工作。我可以触摸复选框并选中它