从文本左侧的开关按钮绘制拇指和跟踪器

时间:2015-01-02 03:07:45

标签: android widget

在开关按钮上设置文本时的默认结果是右侧的拇指/轨道

+-------------+----------+
|             |          |
|  Lorem Ispu | on / off |
|             |          |
+-------------+----------+

如果有任何方法可以将重击/敲击器放在文本的左侧而无需编写自定义小部件,该怎么办?

+-----------+-------------+
|           |             |
|  on / off | Lorem Ipsum |
|           |             |
+-----------+-------------+

谢谢:)

2 个答案:

答案 0 :(得分:2)

我找到的唯一方法是将Linear和TextView包装在LinearLayout中:

    <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <android.support.v7.widget.SwitchCompat
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Your text:"/>
</LinearLayout>

希望它有所帮助。 想法与此处提到的相同:How to show android checkbox at right side?我刚刚颠倒了订单。

答案 1 :(得分:-2)

要设置开关的默认值,您必须在xml中定义此代码

android:checked="true"