【发布时间】:2021-09-25 14:09:30
【问题描述】:
在某些屏幕上,文本和图像重叠。在这种情况下,我想将文本向上移动。
我使用指南将 TextView 放置在百分比位置。这是文本的首选位置。在它下面是一个带有 layout_width="match_parent" 和比例的图像。根据屏幕纵横比,图像将变得足够高以与文本重叠。在这种情况下,我希望文本向上移动。所以我想要文本和图像之间的“最小约束”为 8dp。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guidelineGoldenRatio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.381966" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Keep me from overlapping"
app:layout_constraintTop_toTopOf="@+id/guidelineGoldenRatio"
app:layout_constraintBottom_toTopOf="@+id/guidelineGoldenRatio"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:adjustViewBounds="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/ic_supercat_popular" />
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
标签: android android-constraintlayout