gpt4 book ai didi

android - 如何将 Switch 右对齐? [安卓]

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:48:09 24 4
gpt4 key购买 nike

我有一个带开关的布局。我希望文本位于左侧,实际开关位于右侧。我该怎么做?我知道这是可能的,因为它们在手机设置中是这样的。

现状:

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="15dp"
android:dividerPadding="5dp"
android:orientation="vertical"
android:padding="15dp"
android:scrollbars="vertical"
android:showDividers="middle" >

<Switch
android:paddingBottom="15dp"
android:id="@+id/switch_gprs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:gravity="center_vertical|fill|end"
android:text="@string/gprs" />

<View
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="@color/holo_black" />

<Switch
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:id="@+id/switch_voicemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/voicemail" />

<RelativeLayout
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/number" />

<TextView
android:id="@+id/voicemail_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="TextView" />

</RelativeLayout>

<RelativeLayout
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/email" />

<TextView
android:id="@+id/voicemail_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="TextView" />

</RelativeLayout>

<TextView
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/voicemail_download" />

<View
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="@color/holo_black" />

<Switch
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/redirect" />

<RelativeLayout
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/sim_number" />

<TextView
android:id="@+id/redirect_sim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="TextView" />

</RelativeLayout>

<RelativeLayout
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/redirect_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="TextView" />

<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/redirect_number" />

</RelativeLayout>

最佳答案

只需将宽度设置为match_parent:

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

关于android - 如何将 Switch 右对齐? [安卓],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18630775/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com