歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android設置RadioButton在文字的右邊

Android設置RadioButton在文字的右邊

日期:2017/3/1 10:30:09   编辑:Linux編程
Android設置RadioButton在文字的右邊效果圖如下:

[html]
  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. <TextView
  7. android:id="@+id/radiobutton_textview"
  8. android:layout_width="fill_parent"
  9. android:layout_height="50dip"
  10. android:background="@android:drawable/title_bar"
  11. android:gravity="center_vertical"
  12. android:textAppearance="?android:attr/textAppearanceLarge"
  13. android:textSize="18dip"
  14. android:textStyle="bold" />
  15. <RadioGroup
  16. android:id="@+id/group"
  17. android:layout_width="fill_parent"
  18. android:layout_height="wrap_content"
  19. android:orientation="vertical" >
  20. <RadioButton
  21. android:id="@+id/button1"
  22. android:layout_width="fill_parent"
  23. android:layout_height="50dip"
  24. android:button="@null"
  25. android:drawableRight="@android:drawable/btn_radio"
  26. android:paddingLeft="30dip"
  27. android:text="Android新手"
  28. android:textSize="20dip" />
  29. <View
  30. android:layout_width="fill_parent"
  31. android:layout_height="1px"
  32. android:background="?android:attr/listDivider" />
  33. <RadioButton
  34. android:id="@+id/button2"
  35. android:layout_width="fill_parent"
  36. android:layout_height="50dip"
  37. android:button="@null"
  38. android:drawableRight="@android:drawable/btn_radio"
  39. android:paddingLeft="30dip"
  40. android:text="Android高手"
  41. android:textSize="20dip" />
  42. </RadioGroup>
  43. </LinearLayout>
[java]
  1. package sdfasdf.sadf;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.widget.RadioGroup;
  5. import android.widget.RadioGroup.OnCheckedChangeListener;
  6. import android.widget.TextView;
  7. public class SdfsadfasdfasdffActivity extends Activity {
  8. private TextView textView;
  9. private RadioGroup group;
  10. @Override
  11. public void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.main);
  14. textView = (TextView) findViewById(R.id.radiobutton_textview);
  15. group = (RadioGroup) findViewById(R.id.group);
  16. // 單選按鈕組監聽事件
  17. group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  18. @Override
  19. public void onCheckedChanged(RadioGroup group, int checkedId) {
  20. // 根據ID判斷選擇的按鈕
  21. if (checkedId == R.id.button1) {
  22. textView.setText("Android新手");
  23. } else {
  24. textView.setText("Android高手");
  25. }
  26. }
  27. });
  28. }
  29. }
Copyright © Linux教程網 All Rights Reserved