响应式图像-如何?

时间:2019-04-17 12:40:49

标签: android android-layout android-imageview

在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>

但是随着屏幕的变化,我的图像无法调整尺寸。如何设置图像以调整尺寸并保持与布局更改相同的比例?

1 个答案:

答案 0 :(得分:0)

将此添加到您的图片视图

        android:adjustViewBounds="true"

并设置您的

layout_height="wrap_content"