[英]How I can show the number of items in recyclerview?
In recyclerview, I want only 3 items to show, 在recyclerview中,我只希望显示3个项目,
so I set the width and height with recyclerview but, 所以我用recyclerview设置了宽度和高度,但是
another test device it show 3.2 items to show. 另一个测试设备显示3.2个要显示的项目。
in main activity, 在主要活动中
<android.support.v7.widget.RecyclerView
android:id="@+id/main_activity_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
and in main_activity_recyclerviews view. 并在main_activity_recyclerviews视图中。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" **android:layout_width="90dp"**
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
>
<TextView> ...
</LinearLayout>
In main_activity_recyclerviews view, I change the width and test in A device, it show just 3 items, but test in B device, it shows 3.2items. 在main_activity_recyclerviews视图中,我更改宽度并在A设备中测试,它仅显示3个项目,但在B设备中测试,它显示3.2个项目。
It occurs looks like device display size. 它看起来像设备的显示大小。
How I can show the recyclerview items of appoint size? 如何显示指定尺寸的recyclerview项目?
----------------------update--------------------------- ----------------------更新---------------------------
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_main,parent,false);
view.getLayoutParams().height = changeX;
return new MyViewHolder(view);
}
oncreateviewholder oncreateviewholder
One solution is to set height of each child problematically like 一种解决方案是像这样麻烦地设置每个孩子的身高
view.getLayoutParams().height = getScreenHeight() / VIEWS_COUNT_TO_DISPLAY;
And the screen size like this: 屏幕尺寸如下所示:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics).heightPixels;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.