【问题标题】:How to change the font size of a Radio button ListView?如何更改单选按钮 ListView 的字体大小?
【发布时间】:2013-05-28 15:09:37
【问题描述】:

我找到了许多关于如何自定义 listView 字体大小的解决方案,但是当我尝试实现单选按钮 listview 时,它们都不起作用。每当我尝试应用相同的选项时,单选按钮就会消失。

这是我的代码:

List_item 自定义文本字体

<?xml version="1.0" encoding="utf-8"?>
 <TextView xmlns:
     android="http://schemas.android.com/apk/res/android" 
     android:id="@android:id/text1"  
     android:paddingTop="2dip" 
     android:paddingBottom="3dip" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

实现listView的xml

<ListView
    android:id="@android:id/list"
    android:layout_width="wrap_content"
    android:layout_height="221dp"
    android:layout_weight="0.00" >

</ListView>

<Button
    android:id="@+id/button1"
    android:layout_width="120dp"
    android:layout_height="50dp"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/button_attributes"
    android:text="Proceed" >
</Button>

**(以及我尝试创建 RADIO LISTVIEW 的活动)

没有任何自定义的原始代码有效:

setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_single_choice, slips));

我尝试将自定义列表设置为单选按钮不可见的适配器的代码:

setListAdapter(new ArrayAdapter<String>(this,R.layout.list_item, slips));

感谢任何帮助! :)

【问题讨论】:

    标签: android android-listview radiobuttonlist


    【解决方案1】:

    RadioButton 是不可见的,因为您没有在 list_item.xml 中添加任何 RadioButton

    将您的 list_item.xml 更改为

    <?xml version="1.0" encoding="utf-8"?>
    <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:gravity="center_vertical"
        android:checkMark="?android:attr/listChoiceIndicatorSingle"
        android:paddingLeft="6dip"
        android:paddingRight="6dip"
    />
    

    【讨论】:

    • 解决方案。非常感谢!
    【解决方案2】:

    使用自定义列表视图在列表视图中添加单选按钮,这是一种简单而好的方法 因为如果您想要其他更改而不是自定义是有用的。

    【讨论】:

      猜你喜欢
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-18
      • 2017-11-24
      • 1970-01-01
      相关资源
      最近更新 更多