【发布时间】:2019-09-03 10:24:57
【问题描述】:
我一直面临一个问题,认为是一组多个不正确的定位选择,之前的一些信息:
1 - 可绘制图像的宽度和高度比它适合的要大。 2 - TextView 文本是动态的,但不应超过一行,如果超过一行,则应“剪切”。
我有以下代码:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/icon"
android:text="my small text"
android:lines="1"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/description"
app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/icon"
android:text="description text"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/icon"
app:layout_constraintStart_toEndOf="@id/title"
app:layout_constraintTop_toTopOf="@id/title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@id/description"
android:adjustViewBounds="true"
android:scaleType="fitEnd"
android:src="@drawable/ic_print"
app:layout_constrainedWidth="true"
app:layout_constrainedHeight="true"
android:padding="8dp"
android:layout_width="0dp"
android:layout_height="0dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
一些解释:由于图像非常大,我需要将它定位在左侧,我使用 android:scaleType="fitEnd" 和 android:padding="8dp" >.
结果令人满意:
问题:
当我在标题中放置非常大的文本时,我希望它在 ImageView 实际上将自身限制为 50% 时将其“推”到其极限。
当我实际使用“与 0dp 匹配的约束”时,就像我的 ImageView 有一个“固定”宽度
我已经尝试将 app:layout_constrainedWidth="true" 添加到 id:title 和 id:description(不成功)
【问题讨论】:
-
看看约束布局中的障碍
-
@RohitSuthar 我会的
标签: android android-constraintlayout