【问题标题】:have radio button on list item在列表项上有单选按钮
【发布时间】:2012-04-09 21:09:08
【问题描述】:

我有一个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>

如您在上面看到的,列表的每一行 都由一个 ImageView 和一个 TextView 组成。现在,我想在TextView 旁边有一个单选按钮,如何在我的情况下添加单选按钮?

【问题讨论】:

  • 使用Relativelayoutadd &lt;RadioButton /&gt; end of Textview

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


【解决方案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>

【讨论】:

  • Vipin 你能解释一下问题是什么吗?
  • @robinhood Leem.fin 在我的回答不知道为什么之后编辑了他的问题
  • 他给了一个 xml,他在问如何在文本视图前添加收音机
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-20
  • 1970-01-01
  • 1970-01-01
  • 2010-11-06
相关资源
最近更新 更多