gpt4 book ai didi

java - ConstraintLayout 不适用于某些值

转载 作者:行者123 更新时间:2023-12-02 10:24:55 25 4
gpt4 key购买 nike

我正在使用以下布局

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<ImageView
android:layout_margin="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/mainImage"
android:scaleType="centerInside"
android:src="@drawable/placeholder"
/>


<LinearLayout
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
app:layout_constraintLeft_toRightOf="@+id/mainImage"
app:layout_constraintEnd_toEndOf="parent"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:background="@null"
android:layout_width="match_parent"
android:layout_height="35dp"
android:inputType="text"
android:hint="Patient Name"
android:drawablePadding="10dp"
android:textSize="14sp"
android:id="@+id/name"
/>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#80000000"
/>

<EditText
android:background="@null"
android:layout_width="match_parent"
android:layout_height="35dp"
android:inputType="text"
android:hint="Patient Name"
android:drawablePadding="10dp"
android:textSize="14sp"
android:id="@+id/dob"
android:visibility="visible"
/>


</LinearLayout>

<ListView
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/mainImage"
android:layout_marginTop="45dp"
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>


</android.support.constraint.ConstraintLayout>

结果是

enter image description here

患者姓名等应位于图像右侧, ListView 应位于 ImageView 的底部,为什么它无法识别约束

最佳答案

当您需要占用所有允许的空间时,您需要限制各个方向的 View ,并使用 match_constraint (0dp)

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/mainImage"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_margin="10dp"
android:scaleType="centerInside"
android:src="@drawable/placeholder"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>


<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginStart="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="@+id/mainImage"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@+id/mainImage"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="@+id/mainImage"
app:layout_constraintTop_toTopOf="@+id/mainImage">

<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="@null"
android:drawablePadding="10dp"
android:hint="Patient Name"
android:inputType="text"
android:textSize="14sp"
/>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#80000000"
/>

<EditText
android:id="@+id/dob"
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="@null"
android:drawablePadding="10dp"
android:hint="Patient Name"
android:inputType="text"
android:textSize="14sp"
android:visibility="visible"
/>


</LinearLayout>

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mainImage"/>


</android.support.constraint.ConstraintLayout>

关于java - ConstraintLayout 不适用于某些值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54034850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com