2011-04-05 38 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" />

這可能會導致一些結垢的問題,當你增加了尺寸,但爲了減小它的大小應該工作正常。

相關問題