国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

自定義RadioButton樣式2

2019-11-09 17:26:54
字體:
供稿:網(wǎng)友

先看一下圖: 這里寫圖片描述 上面這種3選1的效果如何做呢?用代碼寫? 其實有更簡單的辦法,忘了RadioButton有什么特性了嗎? 我就用RadioButton實現(xiàn)了如上效果,其實很簡單的。 首先定義一張background,命名為radio.xml,注意該background必須為xml樣式的圖片: 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>

java代碼

<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="預(yù)約服務(wù)" 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”全部設(shè)為null,并且將android:background=”@drawable/radio”設(shè)為剛才新建的圖片。這樣就完成了。 一句代碼都不用寫!

看看豎下來的效果:

這里寫圖片描述

傍邊有圖標(biāo)的怎么辦? 這里寫圖片描述

也很簡單啦,只要在每個RadioButton上加android:drawableLeft=”@drawable/tubiao_0”就可以了。 另外要設(shè)置圖標(biāo)與文字的距離怎么辦? 有一個方法setCompoundDrawablePadding(pad)可以設(shè)置圖標(biāo)與文字的距離,對應(yīng)的屬性為android:drawablePadding。

有了這招完全可以實現(xiàn)類似的n選1效果,看下面: 這里寫圖片描述 這里寫圖片描述

轉(zhuǎn)自:http://gundumw100.iteye.com/blog/1146527


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 二连浩特市| 绵阳市| 班玛县| 青冈县| 吴江市| 云南省| 嘉兴市| 新营市| 宜黄县| 卢氏县| 中宁县| 武功县| 云梦县| 郁南县| 边坝县| 嘉义市| 内黄县| 迁安市| 彰化市| 宿松县| 邵阳市| 桓仁| 沂南县| 石屏县| 视频| 鄄城县| 三明市| 永康市| 肥东县| 汉阴县| 乾安县| 阳信县| 利津县| 化州市| 呼伦贝尔市| 连平县| 湖北省| 泰兴市| 乐昌市| 三原县| 南平市|