【问题标题】:Responsive Image - how to?响应式图像 - 如何?
【发布时间】:2019-09-07 17:09:02
【问题描述】:

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

    将此添加到您的图像视图

            android:adjustViewBounds="true"
    

    并设置你的

    layout_height="wrap_content"
    

    【讨论】:

    • 并设置你的 layout_height="wrap_content"
    • 您可以编辑您的答案,而不是添加评论。
    • 不,wrap_content 让它消失
    猜你喜欢
    • 2021-08-20
    • 1970-01-01
    • 1970-01-01
    • 2017-12-23
    • 2016-03-18
    • 2018-09-06
    • 2023-03-05
    • 2014-07-22
    • 1970-01-01
    相关资源
    最近更新 更多