在列表项上有单选按钮

时间:2012-03-26 10:56:32

标签: android android-layout android-intent android-emulator android-widget

我有ListView

  <ListView
        android:id="@+id/my_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

列表视图的每个项目行的布局为:

<? Xml version = "1.0" encoding = "utf-8"?> 
<LinearLayout 
    xmlns: android = "http://schemas.android.com/apk/res/android" 
    android: orientation = "horizontal" 
    android: layout_width = "fill_parent" 
    android: layout_height = "fill_parent" 
    > 
    <ImageView 
          android: id = "@+id/my_img" 
          android: layout_width = "wrap_content" 
          android: layout_height = "wrap_content" 
          android: layout_gravity = "center_vertical"          
          /> 
    <TextView 
         android: id = "@+id/my_value" 
         android: layout_width = "wrap_content" 
         android: layout_height = "wrap_content" 
         android: textColor = "@drawable/ black" /> 
</ LinearLayout>

如上所示,列表的每个都包含ImageViewTextView。现在,我想在TextView旁边有一个单选按钮,如何在我的情况下添加单选按钮?

1 个答案:

答案 0 :(得分:1)

试试这个

<? Xml version = "1.0" encoding = "utf-8"?> 
<RelativeLayout 
    xmlns: android = "http://schemas.android.com/apk/res/android" 
    android: layout_width = "fill_parent" 
    android: layout_height = "fill_parent" 
    > 
    <ImageView 
          android: id = "@+id/my_img" 
          android: layout_width = "wrap_content" 
          android: layout_height = "wrap_content" 
          android:layout_algnParentLeft="true" 
          android: layout_centerVertical = "true"          
          /> 
    <TextView 
         android: id = "@+id/my_value" 
         android: layout_width = "wrap_content" 
         android: layout_height = "wrap_content" 
         android:layout_toRightOf="@id/my_img"
         android: textColor = "@drawable/ black" /> 
    <RadioButton 
         android: id = "@+id/radio" 
         android: layout_width = "wrap_content" 
         android: layout_height = "wrap_content" 
         android:layout_toRightOf="@id/my_value" /> 

</ RelativeLayout>