RadioButton 自定义控件

在res/drawable新建radiobutton.xml(本案例为video——evaluate.xml)如下

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
         android:state_enabled="true"
         android:state_checked="true"
         android:drawable="@drawable/comment_highlight" />
    <item
         android:state_enabled="true"
         android:state_checked="false"
         android:drawable="@drawable/comment_normail" />  

    <item
         android:state_enabled="true"
         android:state_checked="false"
         android:drawable="@drawable/comment_normail" />
    <item
         android:state_enabled="true"
         android:state_checked="false"
         android:drawable="@drawable/comment_normail" /> 

    <item
         android:state_enabled="true"
         android:state_checked="false"
         android:drawable="@drawable/comment_normail" /> 

</selector>

布局文件:

<?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:background="#f3f3f3"
    android:orientation="vertical" >

    <include layout="@layout/titlebar" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="15dp"
        android:paddingLeft="10dp"
        android:text="对此次服务满意吗?"
        android:textColor="#2e2e2e"
        android:textSize="@dimen/text_size18sp" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="0.8dp"
        android:layout_marginTop="10dp"
        android:background="@color/expertlist_divider_color" />

    <RadioGroup
        android:id="@+id/evaluate_rg"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@color/white"
        android:paddingBottom="8dp"
        android:paddingTop="8dp" > 

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:paddingBottom="10dp"
            android:checked="true"
            android:text="非常满意"
            android:textSize="18sp"
            android:button="@drawable/video_evaluate" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="0.3dp"
            android:layout_marginTop="10dp"
            android:background="@color/expertlist_divider_color" />

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:text="满意"
            android:textSize="18sp"
            android:button="@drawable/video_evaluate" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="0.3dp"
            android:layout_marginTop="10dp"
            android:background="@color/expertlist_divider_color" />

        <RadioButton
            android:id="@+id/radio3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="一般"
            android:textSize="18sp"
            android:button="@drawable/video_evaluate" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="0.3dp"
            android:layout_marginTop="10dp"
            android:background="@color/expertlist_divider_color" />

        <RadioButton
            android:id="@+id/radio4"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="不满意"
            android:textSize="18sp"
            android:button="@drawable/video_evaluate" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="0.3dp"
            android:layout_marginTop="10dp"
            android:background="@color/expertlist_divider_color" />

        <RadioButton
            android:id="@+id/radio5"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="非常不满意"
            android:textSize="18sp"
            android:button="@drawable/video_evaluate" />

        <View
            android:layout_width="fill_parent"
            android:layout_height="0.3dp"
            android:layout_marginTop="10dp"
            android:background="@color/expertlist_divider_color" />
    </RadioGroup>

    <Button
        android:id="@+id/bt_evaluate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/expert_yuye_bg_selector"
        android:text="提交"
        android:textColor="@color/white"
        android:textSize="@dimen/text_size16sp" />

</LinearLayout>

效果,自己可以优化一下再:

时间: 2024-08-02 07:01:39

RadioButton 自定义控件的相关文章

【Android自定义控件】支持多层嵌套RadioButton的RadioGroup

前言 非常喜欢用RadioButton+RadioGroup做Tabs,能自动处理选中等效果,但是自带的RadioGroup不支持嵌套RadioButton(从源码可看出仅仅是判断子控件是不是RadioButton),本文参考RadioGroup修改了一个支持嵌套CompoundButton的控件,非常实用. 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯伯: http://over140.cnblogs.com 正文 /** * 支持嵌套

[WPF 自定义控件]在MenuItem上使用RadioButton

原文:[WPF 自定义控件]在MenuItem上使用RadioButton 1. 需求# 上图这种包含多选(CheckBox)和单选(RadioButton)的菜单十分常见,可是在WPF中只提供了多选的MenuItem.顺便一提,要使MenuItem可以多选,只需要将MenuItem的IsCheckable属性设置为True: Copy <MenuItem IsCheckable="True"/> 不知出于何种考虑,WPF没有为MenuItem提供单选的功能.为了在Menu

Android仿天猫下拉刷新自定义控件

1.概述 控件基于android-Ultra-Pull-to-Refresh做的header定制,继承PtrFrameLayout,把事件分发给里面的RadioGroup,所以两个自定义控件分别叫HoynPtrFrameLayout,HoynRadioGroup. 因为需要PtrFrameLayout里面的一些私有属性:mPtrIndicator,mScrollChecker,所以把PtrFrameLayout代码提取出来,方便定制,使得HoynPtrFrameLayout可以更好的使用. 2.

【自定义控件】自定义属性

做 Android布局是件很享受的事,这得益于他良好的xml方式.使用xml可以快速 有效的为软件定义界面.可是有时候我们总感觉官方定义的一些基本组件不够用,自定义组件就不可避免了.那么如何才能做到像官方提供的那些组件一样用xml 来定义他的属性呢?现在我们就来讨论一下他的用法. 一.在res/values文件下定义一个attrs.xml文件,代码如下: <?xml version="1.0" encoding="utf-8"?>  <resour

Android笔记——Android自定义控件

目录: 1.自定义控件概述 01_什么是自定义控件 Android系统中,继承Android系统自带的View或者ViewGroup控件或者系统自带的控件,并在这基础上增加或者重新组合成我们想要的效果. 02_为什么用自定义控件 系统控件无法满足需求时,需要自定义控件. 系统的控件在不同手机长得不一样,我们希望在不同手机实现相同的效果: 有些手机上的控件长得不好看,希望好看一些. 系统控件的功能有限,需要在基础上增加功能. 03_怎么用自定义控件-三种方式 1.使用系统控件,重新组合,实现自定义

WPF自定义控件与样式(7)-列表控件DataGrid与ListView自定义样式

一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: DataGrid自定义样式: ListView自定义样式: 二.DataGrid自定义样式 DataGrid是常用的数据列表显示控件,先看看实现的效果(动态图,有点大): DataGrid控件样式结构包括以下几个部分: 列头header样式 调整列头宽度的列分割线样式 行样式 行头调整高度样式 行头部样式

Android自定义控件系列之基础篇

一.概述 在android开发中很多UI控件往往需要进行定制以满足应用的需要或达到更加的效果,接下来就通过一个系列来介绍自定义控件,这里更多是通过一些案例逐步去学习,本系列有一些典型的应用,掌握好了大家也可去创新开发出一些更好的UI,本次先通过简单案例掌握一些基础知识--如何在自定义控件中定义属性. 二.实现定制一个简单RadioButton 1.编写类型MRadioButton 扩展RadioButton public class MRadioButton extends RadioButto

WPF自定义控件与样式(12)-缩略图ThumbnailImage /gif动画图/图片列表

原文:WPF自定义控件与样式(12)-缩略图ThumbnailImage /gif动画图/图片列表 一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要针对WPF项目开发中图片的各种使用问题,经过总结,把一些经验分享一下.内容包括: WPF常用图像数据源ImageSource的创建: 自定义缩略图控件ThumbnailImage,支持网络图片.大图片.图片异步加载

WPF自定义控件与样式(10)-进度控件ProcessBar自定义样

一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: ProcessBar自定义标准样式: ProcessBar自定义环形进度样式: 二.ProcessBar标准样式 效果图: ProcessBar的样式非常简单: <!--ProgressBar Style--> <Style TargetType="ProgressBar" x