gpt4 book ai didi

android - 使用 GridLayoutManager 设置 ImageView 的宽度以填充 RecyclerView 内的空白空间(保持纵横比)

转载 作者:行者123 更新时间:2023-12-01 16:00:42 27 4
gpt4 key购买 nike

我有 RecyclerViewGridLayoutManger

RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.movie_posters_recycler_view);
recyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));

每个 RecyclerView 的项目由以下布局表示
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/movie_item_poster_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true" />

</FrameLayout>

目前我有这样的结果

layout1

我想做这个

layout2

最佳答案

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/movie_thumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"/>
</FrameLayout>

这应该工作

关于android - 使用 GridLayoutManager 设置 ImageView 的宽度以填充 RecyclerView 内的空白空间(保持纵横比),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37084016/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com