首页 > 代码库 > Android设置RadioButton在文字的右边

Android设置RadioButton在文字的右边

 效果图如下:

[html] view plaincopy
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <TextView  
  8.         android:id="@+id/radiobutton_textview"  
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="50dip"  
  11.         android:background="@android:drawable/title_bar"  
  12.         android:gravity="center_vertical"  
  13.         android:textAppearance="?android:attr/textAppearanceLarge"  
  14.         android:textSize="18dip"  
  15.         android:textStyle="bold" />  
  16.   
  17.     <RadioGroup  
  18.         android:id="@+id/group"  
  19.         android:layout_width="fill_parent"  
  20.         android:layout_height="wrap_content"  
  21.         android:orientation="vertical" >  
  22.   
  23.         <RadioButton  
  24.             android:id="@+id/button1"  
  25.             android:layout_width="fill_parent"  
  26.             android:layout_height="50dip"  
  27.             android:button="@null"  
  28.             android:drawableRight="@android:drawable/btn_radio"  
  29.             android:paddingLeft="30dip"  
  30.             android:text="Android新手"  
  31.             android:textSize="20dip" />  
  32.   
  33.         <View  
  34.             android:layout_width="fill_parent"  
  35.             android:layout_height="1px"  
  36.             android:background="?android:attr/listDivider" />  
  37.   
  38.         <RadioButton  
  39.             android:id="@+id/button2"  
  40.             android:layout_width="fill_parent"  
  41.             android:layout_height="50dip"  
  42.             android:button="@null"  
  43.             android:drawableRight="@android:drawable/btn_radio"  
  44.             android:paddingLeft="30dip"  
  45.             android:text="Android高手"  
  46.             android:textSize="20dip" />  
  47.     </RadioGroup>  
  48.       
  49. </LinearLayout>  
[java] view plaincopy
 
  1. package sdfasdf.sadf;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.widget.RadioGroup;  
  6. import android.widget.RadioGroup.OnCheckedChangeListener;  
  7. import android.widget.TextView;  
  8.   
  9. public class SdfsadfasdfasdffActivity extends Activity {  
  10.     private TextView textView;    
  11.     private RadioGroup group;    
  12.       
  13.     @Override  
  14.     public void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.         setContentView(R.layout.main);  
  17.         textView = (TextView) findViewById(R.id.radiobutton_textview);    
  18.         group = (RadioGroup) findViewById(R.id.group);    
  19.           
  20.         // 单选按钮组监听事件    
  21.         group.setOnCheckedChangeListener(new OnCheckedChangeListener() {    
  22.     
  23.             @Override    
  24.                 public void onCheckedChanged(RadioGroup group, int checkedId) {    
  25.                 // 根据ID判断选择的按钮    
  26.                     if (checkedId == R.id.button1) {    
  27.                         textView.setText("Android新手");    
  28.                     } else {    
  29.                             textView.setText("Android高手");    
  30.                     }    
  31.                 }    
  32.           });  
  33.     }  
  34. }  

 http://blog.csdn.net/furongkang/article/details/7272512

Android设置RadioButton在文字的右边