【发布时间】:2025-12-21 22:20:12
【问题描述】:
我得到了一个约束布局,里面有五个连续的图像。我的问题是我希望这些图像的大小具有响应性,因此现在无论屏幕宽度有多小,都会显示所有图像。
这是我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="@android:color/transparent">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="55dp"
android:padding="10dp"
android:gravity="center"
android:layout_marginBottom="55dp"
android:text="This ist the title"
app:layout_constraintBottom_toTopOf="@id/smartphone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:textAppearance="@style/introductionTitle"/>
<ImageView
android:id="@+id/smartphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
app:srcCompat="@drawable/ic_smartphone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<ImageView
android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
app:srcCompat="@drawable/ic_next_dark"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/smartphone"/>
<ImageView
android:id="@+id/shop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
app:srcCompat="@drawable/ic_store"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/next"/>
<ImageView
android:id="@+id/next2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
app:srcCompat="@drawable/ic_next_dark"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/shop"/>
<ImageView
android:id="@+id/coffee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
app:srcCompat="@drawable/ic_coffee"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/next2"/>
</android.support.constraint.ConstraintLayout>
目前,这是它在不同屏幕上的样子:
最好将图像水平居中在一起。为了实现这一点,我将它们放在LinearLayout 中,这确实有效,但我无法解决响应问题。
【问题讨论】:
标签: android android-layout android-constraintlayout