【问题标题】:Alignment vertical the switch on Android垂直对齐Android上的开关
【发布时间】:2021-04-28 16:38:04
【问题描述】:

我正在尝试创建一个布局 (Android Studio),我需要在其中垂直对齐各种控件,例如下面屏幕截图中的 Switch。

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:textAlignment="center"
        android:text="Entrée Chaude" />

    <Switch
        android:id="@+id/switchRespectMenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="50px"
        android:switchMinWidth="50dp"
        android:textSize="25sp"
        android:text="RespectMenu : "
        android:checked="false"/>

    <EditText
        android:id="@+id/remarqueRespectMenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="56dp"
        android:ems="10"
        android:hint="Remarque RespectMenu"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.184"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Switch
        android:id="@+id/switchGrammage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="50px"
        android:switchMinWidth="50dp"
        android:textSize="25sp"
        android:text="Grammage  : "
         />

【问题讨论】:

  • 确保使用与问题相关的标签。 uiswitch 是一个与 iOS 开关有关的标签。您还没有指定要使用哪种布局?
  • @HenryTwist 我使用了 Android 布局,但垂直对齐开关在我的 scipt xml 和图片截图上方显示不佳,提前感谢
  • Android 布局?我在问视图是在哪个ViewGroup 中布置的。您的问题上方的ViewGroup 是什么? ConstraintLayout? LinearLayout? RelativeLayout?...
  • @HenryTwist
  • 你想和什么对齐?

标签: android android-layout android-switch


【解决方案1】:

如果您将所有想要的水平线性布局嵌套在垂直线性布局中,它应该可以工作


<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

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

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />

            <Switch
                android:id="@+id/switch2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Switch" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />

            
            <Switch
                android:id="@+id/switch1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Switch" />
        </LinearLayout>
</LinearLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-20
    • 2019-07-02
    • 2013-04-17
    • 2014-12-05
    • 1970-01-01
    相关资源
    最近更新 更多