【问题标题】:how to decrease radio button size in android如何减小android中的单选按钮大小
【发布时间】:2016-12-14 16:02:07
【问题描述】:

我们可以减小 android 中单选按钮的大小吗??

【问题讨论】:

标签: android radio-button


【解决方案1】:

如果您使用单选按钮,那么通常它会从 android-sdk 获取图像资源 例如/android-sdk-macosx/platforms/android-10/data/res/drawable-hdpi

如果你想自定义它,然后从这个文件夹中获取资源并调整它的大小(我得到它的大小为 34 x 48,它调整为 19 x 24) 然后你可以像这样使用它:

这是我的 radio_button.xml

 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/btn_radio_on" android:state_checked="true" android:state_pressed="false"/>
    <item android:drawable="@drawable/btn_radio_off" android:state_checked="false" android:state_pressed="false"/>
    <item android:drawable="@drawable/btn_radio_on_pressed" android:state_checked="true" android:state_pressed="true"/>
    <item android:drawable="@drawable/btn_radio_off_pressed" android:state_checked="false" android:state_pressed="true"/>

</selector>

这是我的 main.xml

 <?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" >

    <RadioGroup
        android:layout_width="fill_parent"
        android:layout_height="30dp"
        android:checkedButton="@+id/first"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/first"
            android:button="@drawable/radio_button"
            android:height="20dp"
            android:width="20dp" />

        <RadioButton
            android:id="@+id/second"
            android:button="@drawable/radio_button"
            android:height="20dp"
            android:width="20dp" />

        <RadioButton
            android:id="@+id/third"
            android:button="@drawable/radio_button"
            android:height="20dp"
            android:width="20dp" />

        <RadioButton
            android:id="@+id/fourth"
            android:button="@drawable/radio_button"
            android:height="20dp"
            android:width="20dp" />
    </RadioGroup>

</LinearLayout>

由于声誉较低,我无法在此处上传图片,因此我提供了资源链接和输出图片。

https://www.dropbox.com/sh/7518zf3onh4su0z/fO7CP7o1EY

【讨论】:

  • 如何以编程方式进行?
【解决方案2】:

据我所知,单选按钮可以完成,但不像其他 EditText 或 TextView..

试试这个代码..

<RadioGroup android:layout_width="fill_parent"               
            android:layout_height="50dp"           
            android:orientation="horizontal"         
            android:checkedButton="@+id/first">  

 <RadioButton android:id="@+id/first"        
      android:width="50dp"        
      android:height="50dp"        
      android:button="@drawable/button_radio"/> 

   <RadioButton android:id="@+id/second"        
      android:width="50dp"     
      android:height="50dp"     
      android:button="@drawable/button_radio"/>

   <RadioButton android:id="@+id/third"
      android:width="50dp"
      android:height="50dp"
      android:button="@drawable/button_radio"/>

   <RadioButton android:id="@+id/fourth"                                          
      android:width="50dp"              
      android:height="50dp"           
      android:button="@drawable/button_radio"/>           
</RadioGroup>

还可以看看这个Sample..这对你有很大帮助..

【讨论】:

【解决方案3】:

减小单选按钮大小的简单方法是:

<RadioButton android:scaleX="0.75" android:scaleY="0.75" />

当您增加尺寸时,它可能会导致一些缩放问题,但对于减小尺寸,它应该可以正常工作。

【讨论】:

  • 这也会增加文字
【解决方案4】:

我认为它不能完成,因为单选按钮是内置的组件并且它的大小是固定的。

【讨论】:

  • 这些组件的可绘制对象可以修改为看起来不同。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-01
  • 2018-12-30
  • 2017-10-15
  • 1970-01-01
  • 2019-11-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多