设置单个项目的高度recyclerview

发布于 2025-02-13 06:10:25 字数 2204 浏览 0 评论 0原文

我正在创建一个允许用户上传视频的应用程序。我希望这些视频都具有相同的高度,但是目前它们会根据数据库中的实际高度和宽度出现。

我在这里检查了近10个问题,但没有一个能够解决我的问题。有人可以帮我吗?

fragment_profile.xml:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragment.ProfileFragment">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/bar">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

<androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:background="#ECEFF1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintDimensionRatio="4:4"
            android:adjustViewBounds="true"
            android:layout_marginTop="20dp"
            android:layout_marginRight="3dp"/>

        </LinearLayout>

    </ScrollView>

</RelativeLayout>

profiffragment.java:

recyclerView = view.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
[RecyclerView][1]LinearLayoutManager linearLayoutManager = new GridLayoutManager(getContext(), 3) {

@Override
        public boolean checkLayoutParams(RecyclerView.LayoutParams lp) {
            // force size of viewHolder here, this will override layout_height and layout_width from xml
            //lp.height = (int) ( getHeight() * 0.75);
            //lp.width = (int) (getWidth() * 0.75);
            return true;
        }
    };
    recyclerView.setLayoutManager(linearLayoutManager);
    postList = new ArrayList<>();
    myFotoAdapter = new MyFotoAdapter(getContext(), postList);
    recyclerView.setAdapter(myFotoAdapter);
    recyclerView.addItemDecoration(new DividerI

recyclerview

I am creating an app that allows users to upload videos. I want the videos to all have the same height but currently they show up according to their actual height and width in the database.

I checked almost 10 questions on here but none were able to solve my problem. Can someone help me ?

fragment_profile.xml:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragment.ProfileFragment">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/bar">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

<androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:background="#ECEFF1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintDimensionRatio="4:4"
            android:adjustViewBounds="true"
            android:layout_marginTop="20dp"
            android:layout_marginRight="3dp"/>

        </LinearLayout>

    </ScrollView>

</RelativeLayout>

ProfileFragment.Java:

recyclerView = view.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
[RecyclerView][1]LinearLayoutManager linearLayoutManager = new GridLayoutManager(getContext(), 3) {

@Override
        public boolean checkLayoutParams(RecyclerView.LayoutParams lp) {
            // force size of viewHolder here, this will override layout_height and layout_width from xml
            //lp.height = (int) ( getHeight() * 0.75);
            //lp.width = (int) (getWidth() * 0.75);
            return true;
        }
    };
    recyclerView.setLayoutManager(linearLayoutManager);
    postList = new ArrayList<>();
    myFotoAdapter = new MyFotoAdapter(getContext(), postList);
    recyclerView.setAdapter(myFotoAdapter);
    recyclerView.addItemDecoration(new DividerI

RecyclerView

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文