如何在Switch的右侧设置文本位置(如CheckBox) [英] How to set text position to the right of a Switch (like CheckBox)

查看:941
本文介绍了如何在Switch的右侧设置文本位置(如CheckBox)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置开关右侧的文本位置,而不是在LinearLayout中对齐Switch和TextView?我试图在我的style.xml按钮中覆盖CheckBox按钮样式,但我不知道如何获取Switch按钮引用?

How to set the text position to the right of a Switch without align a Switch and a TextView in a LinearLayout ? I tried to override the CheckBox button style in my style.xml button but I don't know how to get the Switch button reference ?

推荐答案

有两种方式,但不推荐使用负填充,所以第二种方式。

Two ways are there but as negative padding is not recommended so the 2nd way.

=> 使用单独的文字视图

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:layout_height="wrap_content">
            <Switch
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/switch1" />
            <TextView
                android:layout_width="wrap_content"
                android:text="This is a switch"
                android:layout_height="wrap_content" />
        </LinearLayout>

编辑 - 没有直接的方式,但使用负填充,父布局或任何自定义库。
请参见此处此处。< br>
忘掉这个并使用这个库

EDIT - There's no direct way but using Negative padding, A parent Layout or Any custom library. See here and here.
Forget this and use this library.

这篇关于如何在Switch的右侧设置文本位置(如CheckBox)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆