【问题标题】:Recycler view display item with different size image具有不同尺寸图像的回收站视图显示项目
【发布时间】:2018-06-20 03:07:22
【问题描述】:

我正在使用回收站视图来显示项目,我的项目包括图像和文本。我使用StaggeredGridLayoutManager 来显示这个。

我的布局的一部分:

 <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <android.support.v7.widget.CardView
                android:id="@+id/cvExhibit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                xmlns:cardview="http://schemas.android.com/apk/res-auto"
                cardview:cardCornerRadius="@dimen/cardview_corner_radius"
                cardview:cardUseCompatPadding="true"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <ImageView
                        android:id="@+id/imgExhibit"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:scaleType="fitXY"

                        />
                </LinearLayout>

            </android.support.v7.widget.CardView>

            <ProgressBar
                android:id="@+id/pbItemMainScreen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:elevation="2dp"
                android:visibility="visible"
                android:indeterminateTint="@color/colorBlueLight"
                android:indeterminateTintMode="src_in"
                />

        </RelativeLayout>

结果: result1

我不想让图像的宽度和高度都变大,但结果如下: result2

这里是 result2 的代码:

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <android.support.v7.widget.CardView
                android:id="@+id/cvExhibit"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                xmlns:cardview="http://schemas.android.com/apk/res-auto"
                cardview:cardCornerRadius="@dimen/cardview_corner_radius"
                >
                <ImageView
                    android:id="@+id/imgExhibit"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="fitXY"

                    />
            </android.support.v7.widget.CardView>

            <ProgressBar
                android:id="@+id/pbItemMainScreen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:elevation="2dp"
                android:visibility="visible"
                android:indeterminateTint="@color/colorBlueLight"
                android:indeterminateTintMode="src_in"
                />

        </RelativeLayout>

如何使图像按宽度适合,然后按图像大小自动调整高度?像这样:

My dream result

【问题讨论】:

    标签: android android-layout android-recyclerview


    【解决方案1】:

    请试试这个

    <ImageView
        android:id="@id/imgExhibit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter" />
    

    【讨论】:

    • 现在的输出是什么?
    • 我添加了 android:adjustViewBound ,然后我编辑了 cardview 的 layout_width 和 layout_height。这工作!谢谢你
    • fill_parentdeprecated
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 1970-01-01
    • 2016-07-24
    相关资源
    最近更新 更多