日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

自定義RadioButton樣式2

系統 2223 0
先看一下圖:

自定義RadioButton樣式2
上面這種3選1的效果如何做呢?用代碼寫?
其實有更簡單的辦法,忘了RadioButton有什么特性了嗎?
我就用RadioButton實現了如上效果,其實很簡單的。
首先定義一張background,命名為radio.xml,注意該background必須為xml樣式的圖片:
    
<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
    android:state_checked="false" 
    android:drawable="@drawable/tabswitcher_long" /> 
    <item 
    android:state_checked="true" 
    android:drawable="@drawable/tabswitcher_short" /> 
</selector> 

  

這里我們只要關心state_checked狀態就可以了。所以很簡單的配置。
接下來就是布局文件里面引用這張圖片了:
    
<RadioGroup
		android:gravity="center"
		android:orientation="horizontal"  
        android:layout_width="fill_parent"   
        android:layout_height="wrap_content"
		>
		<RadioButton   
            android:id="@+id/btn_0"  
            android:layout_width="fill_parent"   
        	android:layout_height="wrap_content"
            android:text="最新信息" 
            android:textSize="17.0sp"   
            android:textColor="@android:color/black"  
            android:gravity="center" 
            android:layout_weight="1"
            android:checked="true"
            android:button="@null"
            android:background="@drawable/radio"
            />  
        <RadioButton   
            android:id="@+id/btn_1"
            android:layout_width="fill_parent"   
        	android:layout_height="wrap_content"
            android:text="在線專家"
            android:textSize="17.0sp"
            android:textColor="@android:color/black"  
            android:gravity="center"
            android:layout_weight="1"
            android:button="@null"
          	android:background="@drawable/radio"
            />  
        <RadioButton   
            android:id="@+id/btn_2"
            android:layout_width="fill_parent"   
        	android:layout_height="wrap_content"
            android:text="預約服務"
            android:textSize="17.0sp"
            android:textColor="@android:color/black"  
            android:gravity="center"
            android:layout_weight="1"
            android:button="@null"
          	android:background="@drawable/radio"
            />  
	</RadioGroup>

  

注意將android:button="@null"全部設為null,并且將android:background="@drawable/radio"設為剛才新建的圖片。這樣就完成了。
一句代碼都不用寫!

看看豎下來的效果:
自定義RadioButton樣式2

傍邊有圖標的怎么辦?

自定義RadioButton樣式2
也很簡單啦,只要在每個RadioButton上加android:drawableLeft="@drawable/tubiao_0"就可以了。
另外要設置圖標與文字的距離怎么辦?
有一個方法setCompoundDrawablePadding(pad)可以設置圖標與文字的距離,對應的屬性為android:drawablePadding。

有了這招完全可以實現類似的n選1效果,看下面:
自定義RadioButton樣式2


應用:
http://www.iteye.com/topic/1116261#2256664

自定義RadioButton樣式2


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 司法| 登封市| 浙江省| 隆化县| 渭源县| 庆安县| 鹰潭市| 南雄市| 百色市| 文成县| 桂阳县| 凤山县| 仁寿县| 岳阳市| 察哈| 拉孜县| 兴安盟| 合阳县| 凭祥市| 涿州市| 南澳县| 磴口县| 霍邱县| 元阳县| 泊头市| 蒙阴县| 资兴市| 塔城市| 巴彦县| 永安市| 临清市| 乐昌市| 杂多县| 黔南| 布尔津县| 同心县| 汨罗市| 微山县| 滦南县| 阿勒泰市| 哈巴河县|