2010-06-10 151 views
19

我在mein App中有很多RadioButton。 RadioButton對我來說太大了。有什麼辦法讓它變小嗎?Android:如何更改RadioButton的大小

+0

我想你可以寫你自己的控制,但要記住的是,製造控制太小可以使它更難一些用戶準確命中控制當處於觸摸模式時。這會降低你的應用程序的可用性。 – codinguser 2010-06-10 15:39:34

+0

我找到了這個解決方案,在這裏看到我的答案 [https://stackoverflow.com/a/44310577/6112256](https://stackoverflow.com/a/44310577/6112256) – 2017-06-01 14:46:50

回答

12

無法完成,單選按鈕是一個內置的控制組件,因此它的大小是固定的。

+0

非常感謝! – TianDong 2010-06-13 12:49:49

+1

做起來可能並不容易,但這是可能的;請參閱http://stackoverflow.com/a/4787260/3063884 – CJBS 2015-02-05 23:18:06

+2

請不要回復esp。負面評論爲「不能做」等等,而不是確定的! 請參閱,邁克爾有一個簡單和可行的解決方案! – Apostolos 2016-11-06 10:11:41

14

可以來完成,但並不作爲設置Layout_Width和Layout_height與EditTexts那樣簡單,按鈕等要修改的尺寸/像一個複選框/單選按鈕的圖的樣子使用「背景」和「按鈕「屬性來指定您自己的繪圖。

這是一個較舊的頁面,以及現在的位置是不同的,但是這會給你一個想法: http://www.anddev.org/tutorial_change_look_of_checkbox-t4553.html

+0

請參閱邁克爾簡單可行的解決方案! – Apostolos 2016-11-06 10:12:09

0
<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> 
22

一個快速哈克的解決辦法是縮放按鈕向下:

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

這對於更小的工作很好。

對於變大,這往往會導致容器視圖的一些裁剪,因此您可能必須對RadioGroup的高度/寬度進行硬編碼以適應縮放的按鈕。該按鈕可繪製也得到明顯像素化你去較大,所以如果你想要的東西,3倍大它不是一個真正偉大的...

+0

並添加android:textSize =「[size] sp」也會縮放單選按鈕標籤,但匹配按鈕和標籤大小需要更多的硬代碼... – sepehr 2016-07-25 19:26:26

+0

謝謝:)其工作非常棒! :) – 2016-08-24 07:01:10

+0

縮小按鈕尺寸,但在它們之間留下更大的空間 – 2017-10-12 09:18:47

0

我已經通過調整自身單選按鈕

的TEXTSIZE像這樣

做到了這一點
android:textSize="20sp" 

然後適用於我的代碼;

<RadioGroup 
    android:id="@+id/checkboxRadioButton" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:orientation="horizontal"> 

    <RadioButton 
     android:id="@+id/rb1" 
     style="@android:style/Widget.CompoundButton.CheckBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/checkBoxMargin" 
     android:text="YES" 
     android:textSize="20sp" /> 
    ... 

希望這有助於有人