2011-04-05 111 views
6

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

+0

http://stackoverflow.com/questions/4259295/how-can-i-set-the-width-of-radio-buttons-to-change-with-regards-to-screen-size是您的解决方案。这里是另一篇文章[变化的外观CheckBox的(http://www.anddev.org/tutorial_change_look_of_checkbox-t4553.html) – 2011-04-05 05:10:59

回答

4

据我所知单选按钮可以完成,但不会像其他的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。 。这将帮助你很多..

+0

感谢侯赛因.......... – user671005 2011-04-05 06:18:09

+0

还有一件事如何使它可检查的,当我点击任何按钮,这些林 – user671005 2011-04-05 06:18:49

+0

的不知道这一点,但我认为ü必须使用StateListDrawable ..只要有一起来看看这两个样品。 U可以去了解的东西.. http://heliodorj.blogspot.com/2009/04/androids-statelistdrawable-example.html和http://developer.android.com/reference/android/graphics/drawable/StateListDrawable。 HTML – Hussain 2011-04-05 06:30:43

-2

我认为它不能做,因为单选按钮是在组件中构建的,并且它的大小是固定的。

+1

这些组件的图形内容可以进行修改,以看起来不同。 – Bananeweizen 2012-05-10 19:37:24

4

如果您使用单选按钮,然后通常它需要从android-sdk 例如图像资源。/android-sdk-macosx/platforms/android-10/data/res/drawable-hdpi

如果你想定制它,那么从这个文件夹中获取资源并调整它的大小(我知道它的大小是34×48调整为19×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> 

由于少[R名誉我不能在这里上传图片,所以我给链接资源和输出图像。

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

4

一个简单的方法来降低单选按钮的大小可以是:

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

这可能会导致一些结垢的问题,当你增加了尺寸,但为了减小它的大小应该工作正常。