【问题标题】:how to change direction of checkbox android [duplicate]如何更改复选框android的方向[重复]
【发布时间】:2012-12-19 20:56:51
【问题描述】:

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

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

【问题讨论】:

标签: android checkbox


【解决方案1】:

我认为最好使用CheckedTextView 来满足您的要求

【讨论】:

  • CheckedTextViews 适用于 ListViews。
【解决方案2】:

看看

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 中,以下方法处理两个复选框的点击事件:

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
  }  
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-15
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    • 1970-01-01
    • 2014-06-16
    • 1970-01-01
    • 2014-04-04
    相关资源
    最近更新 更多