Radiobutton也来做tab标签

Android进阶之UI深度定制系列(二)

                                          Radiobutton也来做tab标签

效果图:

XML布局:

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

        <RadioButton
            android:id="@+id/radio0"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/XXX"
            android:button="@drawable/none"
            android:checked="true"
            android:drawableTop="@drawable/yyy"
            android:text="RadioButton" />

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/xxx"
            android:button="@drawable/none"
            android:drawableTop="@drawable/yyy"
            android:text="RadioButton" /> 

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/xxx"
            android:button="@drawable/none"
            android:drawableTop="@drawable/yyy"
            android:text="RadioButton" />

    </RadioGroup>

 

重要属性:

android:drawableTop,android:button,android:background

随着ADT不断升级,可视化的UI编辑变得更加方便高效,通过Properties面板,能够快捷的查询设置UI组件各种属性,
理解RadioButton是实现个性化定制前提,android:drawableTop表示组件内相对上方的图片资源,默认是没有的;android:button表示我们平时看到的圆圈Radio,是一个drawable资源而不是按钮id;android:background当然表示整个RadioBtton的背景图片。
为了时三个RadioButton能够均匀占据屏幕的宽,设置layout_width为match_parent,同时设置他们的layout_weight为一,即在分配宽度时得到相同的优先级。
优势:
保持选中状态,实现不同视觉效果,而通常的做法只能在单击或触摸时有效果的变化,而本例将实现这种效果的固化,就是利用了RadioButton的checked属性

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值