这个用于控制每个radiobutton之间的距离一致。
android:layout_weight="1"
以下3个属性是自定义radiobutton的图片
android:background="@null"
android:button="@null"
android:drawableLeft="@drawable/btn_radio_fee"

注意:不能使用android:layout_marginRight、android:paddingLeft
不管是在布局文件中还是在代码里写,不同的屏幕分辨率会不一致。





/res/drawable-hdpi该目录下有2中图片,一张是选中状态的,一张是位选中状态


创建xml:/res/drawable/btn_radio_fee.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/radio_unchecked"/>    <item android:state_checked="true"  android:drawable="@drawable/radio_checked"/>    <item android:state_selected="true"  android:drawable="@drawable/radio_checked"/>    <item android:state_pressed="true"  android:drawable="@drawable/radio_checked"/> </selector>


创建xml:/res/layout/activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin" >    <RadioGroup        android:id="@+id/feeGroup"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_marginRight="20dp"        android:layout_marginTop="20dip"        android:orientation="horizontal" >        <RadioButton            android:id="@+id/feerb1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="@null"            android:button="@null"            android:drawableLeft="@drawable/btn_radio_fee"            android:gravity="center"            android:text="20"            android:textColor="#ff000000"            android:textSize="12sp" />        <RadioButton            android:id="@+id/feerb2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="@null"            android:button="@null"            android:drawableLeft="@drawable/btn_radio_fee"            android:gravity="center"            android:text="30"            android:textColor="#ff000000"            android:textSize="12sp" />        <RadioButton            android:id="@+id/feerb3"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="@null"            android:button="@null"            android:checked="true"            android:drawableLeft="@drawable/btn_radio_fee"            android:gravity="center"            android:text="50"            android:textColor="#ff000000"            android:textSize="12sp" />        <RadioButton            android:id="@+id/feerb4"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="@null"            android:button="@null"            android:drawableLeft="@drawable/btn_radio_fee"            android:gravity="center"            android:text="100"            android:textColor="#ff000000"            android:textSize="12sp" />        <RadioButton            android:id="@+id/feerb5"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="@null"            android:button="@null"            android:drawableLeft="@drawable/btn_radio_fee"            android:gravity="center"            android:text="200"            android:textColor="#ff000000"            android:textSize="12sp" />    </RadioGroup></RelativeLayout>



package com.example.radiobtn2;import android.app.Activity;import android.os.Bundle;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}}

更多相关文章

  1. TextView 文字加图片显示效果
  2. Android常用控件六之图片框(ImageView)
  3. android状态栏工具类
  4. android检查手机网络状态
  5. Android Imageview 图片居左居右,自定义圆角
  6. android 加载图片到gallery
  7. 有关XML的点击状态背景图的设置
  8. Android 图片倒影和setXfermode
  9. android button 正常状态,按下状态

随机推荐

  1. 浅谈MySQL中float、double、decimal三个
  2. MySQL 连接查询的原理和应用
  3. MySQL中int(n)后面的n到底代表的是什么意
  4. MySQL如何使用时间作为判断条件
  5. 详解MySQL 数据库范式
  6. MySQL中表的几种连接方式
  7. MySQL 子查询和分组查询
  8. 一种简单的ID生成策略: Mysql表生成全局
  9. MySQL limit分页大偏移量慢的原因及优化
  10. MySQL主从复制原理以及需要注意的地方