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属性


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM