android - 复选框和 TextInputLayout 在线性布局内未正确对齐
问题描述
我在衬里布局中有两个复选框和一个 TextInputLayout。但他们没有得到正确渲染。复选框正在向下移动。我尝试了一切,但它们没有对齐。
我的代码如下:
<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
它会解决你的问题
尝试这个
<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>
推荐阅读
- swift - 图像未在 imageView 中显示
- c# - 如何使用 Identity Server 4 撤销或使令牌无效?
- android - 如何知道在哪里寻找 android 手机上的媒体目录?
- python - 用python抓取谷歌搜索url列表
- json - 将 Firebase 备份加载到 bigquery 时出现“解析 JSON 失败:字符串中应有结束引号”错误
- android - 为什么 XML 元素在我的 android studio 模拟器上不可见?
- java - 帧缓冲区图像查看器 (FBI) 在作为进程执行时失败 - Java
- c# - 来自 UserValidator 的身份 c# .net core CustomUserValidator
- python - GridSearchCV 期间的 Python 缩放
- assembly - 如何在我的 x86 汇编代码中使用 mov si, word[ecx] 和 MASM?