TextView 右侧的 SwitchCompat 被推到看不见的地方
SwitchCompat right of TextView gets pushed out of sight
我有一个带有两个 TextView 和一个 SwitchCompat 的 CardView 布局。
现在开关在左边,文本在它的右边(垂直)。我想要这种布局相反的方式,例如在应用程序的 Android 通知设置中:
我的问题是,当我 "turn my current layout around" 时,当 textView 太长时,开关会被推到右边。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingRight="20dp"
android:paddingLeft="16dp"
android:id="@+id/relative">
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp" />
<TextView
android:id="@+id/textView_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/switch_card"
android:singleLine="false"
android:text="@string/title_card"
android:textColor="@color/text_black"
android:textSize="22dp" />
<TextView
android:id="@+id/textView_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView_title"
android:layout_toRightOf="@id/switch_card"
android:paddingTop="10dp"
android:singleLine="false"
android:text="@string/reminder_card"
android:textColor="@color/text_grey"
android:textSize="18dp" />
</RelativeLayout>
能否请您帮我更改布局以使其适合屏幕截图之一?
试试这个:将 SwitchCompat 与 righParent 对齐并为您正在使用的 TextView 留出一些余量的技巧,这样它们就不会与 SwitchCompat 重叠
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingRight="20dp"
android:paddingLeft="16dp"
android:id="@+id/relative">
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp" />
<TextView
android:id="@+id/textView_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:singleLine="false"
android:text="@string/title_card"
android:textColor="@color/text_black"
android:textSize="22dp" />
<TextView
android:id="@+id/textView_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView_title"
android:layout_marginRight="40dp"
android:paddingTop="10dp"
android:singleLine="false"
android:text="@string/reminder_card"
android:textColor="@color/text_grey"
android:textSize="18dp" />
</RelativeLayout>
希望这对您有所帮助
祝你好运!
我有一个带有两个 TextView 和一个 SwitchCompat 的 CardView 布局。
现在开关在左边,文本在它的右边(垂直)。我想要这种布局相反的方式,例如在应用程序的 Android 通知设置中:
我的问题是,当我 "turn my current layout around" 时,当 textView 太长时,开关会被推到右边。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingRight="20dp"
android:paddingLeft="16dp"
android:id="@+id/relative">
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp" />
<TextView
android:id="@+id/textView_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/switch_card"
android:singleLine="false"
android:text="@string/title_card"
android:textColor="@color/text_black"
android:textSize="22dp" />
<TextView
android:id="@+id/textView_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView_title"
android:layout_toRightOf="@id/switch_card"
android:paddingTop="10dp"
android:singleLine="false"
android:text="@string/reminder_card"
android:textColor="@color/text_grey"
android:textSize="18dp" />
</RelativeLayout>
能否请您帮我更改布局以使其适合屏幕截图之一?
试试这个:将 SwitchCompat 与 righParent 对齐并为您正在使用的 TextView 留出一些余量的技巧,这样它们就不会与 SwitchCompat 重叠
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingRight="20dp"
android:paddingLeft="16dp"
android:id="@+id/relative">
<android.support.v7.widget.SwitchCompat
android:id="@+id/switch_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp" />
<TextView
android:id="@+id/textView_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:singleLine="false"
android:text="@string/title_card"
android:textColor="@color/text_black"
android:textSize="22dp" />
<TextView
android:id="@+id/textView_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView_title"
android:layout_marginRight="40dp"
android:paddingTop="10dp"
android:singleLine="false"
android:text="@string/reminder_card"
android:textColor="@color/text_grey"
android:textSize="18dp" />
</RelativeLayout>
希望这对您有所帮助
祝你好运!