设置单个项目的高度recyclerview
我正在创建一个允许用户上传视频的应用程序。我希望这些视频都具有相同的高度,但是目前它们会根据数据库中的实际高度和宽度出现。
我在这里检查了近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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论