Android UI设计中RadioButton显示在右边

先上代码:

其中注释的代码,是之前想要实现在右边,发现这样写,不能监听到radiobutton的状态,不思其解,或者是不能这么写,后来查查资料,原来可以这么做。代码是参考ahutzh大大的,的,收益良多,网址:http://blog.csdn.net/ahutzh/article/details/6324564

interceptorselection.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#F0F0F0"
android:orientation="vertical" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#FFFFFF"
android:orientation="vertical" >

<RadioGroup
android:id="@+id/radiogroup_ItcSelect"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<RadioButton
android:id="@+id/radioButton1"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:paddingLeft="10dip"
android:text="拦截黑名单里的人"
android:textColor="#000000"
android:textSize="20dip" />

<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="?android:attr/listDivider" />

<RadioButton
android:id="@+id/radioButton2"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:paddingLeft="10dip"
android:text="只接收白名单里的人"
android:textColor="#000000"
android:textSize="20dip" />

<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="?android:attr/listDivider" />

<RadioButton
android:id="@+id/radioButton3"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:button="@null"
android:drawableRight="@android:drawable/btn_radio"
android:paddingLeft="10dip"
android:text="拦截所有人"
android:textColor="#000000"
android:textSize="20dip" />

<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="?android:attr/listDivider" />
<!--
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="只接收白名单里的人" />

<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="拦截所有人" />

<RadioButton
android:id="@+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>

-->
</RadioGroup>
</LinearLayout>

</LinearLayout>


InterceptWhoActivity.java

package com.changeandce.interceptor;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class InterceptWhoActivity extends Activity {

RadioGroup mRadioGroup;
RadioButton mRadio1, mRadio2, mRadio3;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.interceptorselection);
init();

}

private void init() {
// TODO Auto-generated method stub
mRadioGroup = (RadioGroup) findViewById(R.id.radiogroup_ItcSelect);
mRadio1 = (RadioButton) findViewById(R.id.radioButton1);
mRadio2 = (RadioButton) findViewById(R.id.radioButton2);
mRadio3 = (RadioButton) findViewById(R.id.radioButton3);

mRadioGroup
.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub

switch (checkedId) {
case R.id.radioButton1:
DisplayToast("第一个");
break;
case R.id.radioButton2:
DisplayToast("第二个");
break;
case R.id.radioButton3:
DisplayToast("第三个");
break;
}
}
});
}

public void DisplayToast(String str) {
Toast toast = Toast.makeText(this, str, Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP, 0, 220);
toast.show();
}
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值