簡體   English   中英

具有不同尺寸圖像的回收者視圖顯示項目

[英]Recycler view display item with different size image

我正在使用回收站視圖顯示項目,我的項目包括圖像和文本。 我使用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>

如何按寬度適合圖像,然后根據圖像尺寸自動適合高度? 像這樣:

我的夢想結果

請嘗試這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM