您需要将图片保存在一个框架中,问题是在具有不同分辨率的设备上显示时。例如,图片显示了一个 nexus 和一个平板电脑
这是布局代码
*<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ru.yandex.matu1.toddlersbook.BookCardActivity">
<ImageView
android:id="@+id/imageView6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:srcCompat="@drawable/fonhdpi"
tools:ignore="ContentDescription" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="40dp">
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:foreground="@drawable/framehdpi"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.488"
tools:ignore="ContentDescription">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_margin="45dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.102"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.583"
app:srcCompat="@drawable/cat1"
tools:ignore="ContentDescription" />
</FrameLayout>
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_weight="0.2"
android:background="@drawable/buttonhdpi"
android:scaleType="fitCenter"
android:text="@string/download_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.555"
app:layout_constraintStart_toEndOf="@+id/frameLayout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.498"
app:srcCompat="@drawable/buttonhdpi"
tools:ignore="ContentDescription" />
</LinearLayout>
</FrameLayout>*
你能告诉我如何使图片始终在框架中吗?


内部图片的约束
FrameLayout不起作用(那里不需要它们)。相反,您需要指定属性scaleType,adjustViewBounds以便在保持比例的同时拉伸图像: