【问题标题】:draw thumb and tracker from switch button on left of text从文本左侧的切换按钮绘制拇指和跟踪器
【发布时间】:2015-02-28 11:27:23
【问题描述】:

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

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

要知道是否有任何方法可以将重击/定位器放置在文本的左侧,而无需编写自定义小部件:

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

谢谢:)

【问题讨论】:

    标签: android widget


    【解决方案1】:

    我发现的唯一方法是将 Switch 和 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?我只是颠倒了顺序。

    【讨论】:

      【解决方案2】:

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

      android:checked="true" 
      

      【讨论】:

      • 您的视图需要某种类型的自定义选择器吗?
      • 没有。切换视图对我来说已经足够了,但我真的需要文本左侧的拇指和跟踪器:/
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 2017-01-29
      • 1970-01-01
      相关资源
      最近更新 更多