如何在 android 中将文本方向更改为向右滑动开关?
how to change text direction to the right slide of switch in android?
在默认模式下,Switch
的文本位于 ON/OFF 状态的左侧。我想将此文本的方向更改为右侧幻灯片。我怎样才能做到这一点?
我已经尝试过此 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>
或者你可以这样做:
<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"
在默认模式下,Switch
的文本位于 ON/OFF 状态的左侧。我想将此文本的方向更改为右侧幻灯片。我怎样才能做到这一点?
我已经尝试过此 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>
或者你可以这样做:
<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"