如何改变复选框android的方向

时间:2012-12-19 12:48:21

标签: android checkbox

  

可能重复:
  How to Set the Checkbox on the right side of the text

我想更改android中复选框的方向,使文本位于左侧,复选框位于右侧。你能帮帮我吗?

2 个答案:

答案 0 :(得分:1)

我认为最好根据您的要求使用CheckedTextView

答案 1 :(得分:0)

看看

http://developer.android.com/guide/topics/ui/controls/checkbox.html

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
<CheckBox android:id="@+id/checkbox_meat"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/meat"
    android:onClick="onCheckboxClicked"/>
<CheckBox android:id="@+id/checkbox_cheese"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/cheese"
    android:onClick="onCheckboxClicked"/>
</LinearLayout>

在托管此布局的Activity中,以下方法处理两个复选框的click事件:

public void onCheckboxClicked(View view) {
   // Is the view now checked?
  boolean checked = ((CheckBox) view).isChecked();

 // Check which checkbox was clicked
  switch(view.getId()) {
    case R.id.checkbox_meat:
        if (checked)
            // Put some meat on the sandwich
        else
            // Remove the meat
        break;
    case R.id.checkbox_cheese:
        if (checked)
            // Cheese me
        else
            // I'm lactose intolerant
        break;
    // TODO: Veggie sandwich
  }  
 }