如何在android中将文本方向更改为开关的右侧幻灯片?

如何在android中将文本方向更改为开关的右侧幻灯片?,android,text,switch-statement,Android,Text,Switch Statement,在默认模式下,开关的文本位于开/关状态的左侧。我想将此文本的方向更改为右侧幻灯片。我该怎么做 我已经尝试了此xml代码,但不起作用: <Switch android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/switch1" android:layout_gravity:"right" android:layout_margin="@dimen/abc_dropdowni

在默认模式下,
开关的文本位于开/关状态的左侧。我想将此文本的方向更改为右侧幻灯片。我该怎么做

我已经尝试了此
xml
代码,但不起作用:

<Switch
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/switch1"
android:layout_gravity:"right"
android:layout_margin="@dimen/abc_dropdownitem_text_padding_right"/>

如果这不可行,您可以尝试以下方法

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <Switch
            android:id="@+id/switch_gprs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="false"
            android:paddingBottom="15dp"
            />

        <TextView

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="false"
            android:paddingBottom="15dp"
            android:layout_toRightOf="@+id/switch_gprs"
            android:text="sometext"/>


    </RelativeLayout>

如果这不可行,您可以尝试以下方法

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <Switch
            android:id="@+id/switch_gprs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="false"
            android:paddingBottom="15dp"
            />

        <TextView

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="false"
            android:paddingBottom="15dp"
            android:layout_toRightOf="@+id/switch_gprs"
            android:text="sometext"/>


    </RelativeLayout>

或者您可以执行以下操作:

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="My Switch"/>

</LinearLayout>

或者您可以执行以下操作:

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="My Switch"/>

</LinearLayout>

您可以使用以下功能:

android:layoutDirection=“rtl”

您可以使用:


android:layoutDirection=“rtl”

此问题的可能重复已重复,并且已经有了答案,与您的答案相同,但有解释。嗯,我没有看到那个答案,非常感谢。这个问题是重复的,已经有了答案,与你的答案相同,但有解释。嗯,我没有看到那个答案,非常感谢。