Android中如何設置RadioButton在文字的右邊,圖標在左邊


from:http://blog.csdn.net/sunnyfans/article/details/7901592?utm_source=tuicool&utm_medium=referral

 

Android 中如何設置RadioButton在文字的右邊,圖標在左邊???

解決方法  :
第一步:
android:button="@null"這條語句 將原來系統的 RadioButton圖標給隱藏起來。
第二步:
 android:drawableRight="@android:drawable/btn_radio"這條語句
在原來圖標的右邊添加一個系統自帶的btn_radio圖標,我想RadioButton就是在 btn_radio圖標上進行封裝而已。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
           android:button="@null"
            android:checked="true"
            android:drawableRight="@android:drawable/btn_radio"
            android:paddingLeft="10dp"
            android:text="RadioButton" />

        <RadioButton
            android:id="@+id/button2"
            android:layout_width="319dp"
            android:layout_height="wrap_content"
            android:button="@null"
            android:drawableRight="@android:drawable/btn_radio"
            android:paddingLeft="10dp"
            android:text="RadioButton" />

    </RadioGroup>
</LinearLayout>

demo下載
http://download.csdn.net/detail/sunnyfans/4521592

附參考網站:
http://www.haogongju.net/art/1422253


小結:

今天在實現RadioGroup單選時,要求文字在左邊,選擇圖標在右邊,而android系統自帶的RadioGroup是圖標在左邊,文字在右邊,既然我有這個需求,遇到這個問題,那么肯定有其他人也有這個需求,於是也就應該有實現它的方法。因為問題已經發生了,這個世界也就是在不斷解決未知問題的過程中不斷發展進步,即:需求,問題是發明、發展的原始推動力。知識是為解決問題,或者描述某現象的而誕生。所以以后不管遇到什么問題,不要畏懼,既然問題已經發生了,即一定會有解決它的辦法,這時就需要自己去思考,思考這個問題發生的環境,分析問題,然后定位問題原因(二分法)<先猜測,再求證>, 定位后再思考如何去解決。不斷提醒自己養成這種遇到問題,分析問題,進而嘗試去解決問題的習慣。

知識收獲:
認識到android系統圖標的重要性,可以這樣使用:
 android:button="@null"將圖標給隱藏,然后再用android:drawableRight="@android:drawable/btn_radio"在右邊再生成一個圖標,再用android:text="文字內容"在隱藏圖標的位置顯示文字。
反復思考:
 android:button="@null"
android:drawableRight="@android:drawable/btn_radio
這提供了一種通用方法。

附:demo下載
http://download.csdn.net/detail/sunnyfans/4521592

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM