Android 复选框和TextInputLayout在线性布局中未正确对齐
我在一个线性布局中有两个复选框和一个TextInputLayout。但他们没有得到适当的渲染。复选框正在向下移动。我什么都试过了,但他们没有对齐 我的代码如下:Android 复选框和TextInputLayout在线性布局中未正确对齐,android,android-layout,Android,Android Layout,我在一个线性布局中有两个复选框和一个TextInputLayout。但他们没有得到适当的渲染。复选框正在向下移动。我什么都试过了,但他们没有对齐 我的代码如下: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" androi
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layoutSysCardNo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_weight="2"
app:boxBackgroundColor="@color/white_50"
app:counterMaxLength="10">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/sysCardNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/field_enter_sys_job_no"
android:inputType="number" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/hmsiWarranty"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:text="@string/vehicle_delievered" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/extWarranty"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:text="@string/vehicle_delievered" />
</LinearLayout>
输出如下所示
只需在您的
线性布局中使用android:gravity=“center”
即可解决您的问题
试试这个
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layoutSysCardNo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_weight="2"
app:boxBackgroundColor="@color/white_50"
app:counterMaxLength="10">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/sysCardNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/field_enter_sys_job_no"
android:inputType="number" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/hmsiWarranty"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:text="@string/vehicle_delievered" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/extWarranty"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:text="@string/vehicle_delievered" />
</LinearLayout>