android - 为什么 layout_weight 在 TextInputLayout 的孩子中不起作用?
问题描述
我有以下内容:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha=".9"
android:background="@color/light_gray_search"
android:padding="16dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1"
app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:importantForAccessibility="no"
app:srcCompat="@drawable/myImage" />
<AutoCompleteTextView
android:id="@+id/myAutoCompleteTextView"
android:layout_weight="0.8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/myAutoHint"
android:imeOptions="actionNext"
android:inputType="textPersonName"
android:maxLines="1"/>
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
知道TextInputLayout
extends LinearLayout
,并且我使用LinearLayout
xml属性(weightSum
,,, orientation
)layout_weight
首先对我的imageView进行水平对齐,然后是autoCompleteText,
为什么这不起作用?
当前结果:即使在分配layout_weight
.
解决方案
实际上找到了答案,将其发布在这里以供将来参考:
添加一个LinearLayout
, 并分别拥有LinearLayout
beImageView
和TextInputLayout
on 水平方向的子级。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
android:orientation="horizontal"
android:weightSum="1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:importantForAccessibility="no"
app:srcCompat="@drawable/myImage"
android:layout_gravity="center_vertical"/>
<com.google.android.material.textfield.TextInputLayout
..
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.9"
..>
<AutoCompleteTextView
../>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
推荐阅读
- selenium - 使用 Selenium + Chrome 驱动程序 + Browsermob 代理登录仅在我添加另一个代理时才有效 -> 为什么?
- javascript - 使用 Bootstrap 轮播错误消息获取无法读取未定义的属性“offsetWidth”
- c# - 如何使用 C# 模式匹配与元组
- c++ - 带有 Clang 10 的显式模板实例化的 ~queue 的未定义引用
- android - kotlin 中的运行时异常
- algorithm - 通过大师定理和迭代方法的递归关系 - 不同的对数底
- amazon-s3 - s3cmd 将文件从 tar 标准输入:[Errno 32] 损坏的管道
- r - R 声称 doParallel 所依赖的包不可用,即使它们已安装并且可以加载
- javascript - 你好 !反应问题我需要事件处理程序的帮助
- c# - System.Data.SqlClient.SqlException:'无效的列名'Project_ID_Backend'。'