响应式图像 - 如何?

问题描述 投票:0回答:1

在Android XML中我有我的图像:

<android.support.constraint.ConstraintLayout
            android:id="@+id/cl_movie_poster"
            android:layout_width="41dp"
            android:layout_height="0dp"
            app:layout_constraintDimensionRatio="41:63"
            app:layout_constraintStart_toStartOf="@id/gl_left_gutter"
            app:layout_constraintTop_toTopOf="@id/gl_top_gutter">

            <ImageView
                android:id="@+id/movie_poster"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@string/lbl_poster_image"
                android:scaleType="fitCenter"
                app:nullableImageUrl="http://www.example.com/image.png"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                />

            <ImageView
                style="@style/MoviePosterDecorator"
                android:id="@+id/movie_image_decorator"
                android:layout_height="24dp"
                android:elevation="0dp"
                android:src="@drawable/decorator_dow_friday"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                android:contentDescription="@null"
                />
</android.support.constraint.ConstraintLayout>

但是我的图像不会随着屏幕的变化调整大小。如何设置图像以调整大小并保持与布局更改相同的比例?

android android-layout android-imageview
1个回答
0
投票

将其添加到您的imageview

        android:adjustViewBounds="true"

并设置你的

layout_height="wrap_content"
© www.soinside.com 2019 - 2024. All rights reserved.