如何显示RecyclerView项目的确切数字? [英] How to show exact number of items in RecyclerView?
问题描述
我想确切的证明(如3项)的RecyclerView。我们的Web应用程序的显示是这样的:
如果我移动项目:
在Android中,我显示使用RecyclerView图片:
如何显示RecyclerView的可见区域恰好3个项目?如何避免以显示半壁江山的项目?这可能吗?
RecyclerView:
< android.support.v7.widget.RecyclerView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =130dp
机器人:ID =@ + ID / rvProducts/>
在回收站视图中的一项:
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直的android:layout_width =match_parent
机器人:layout_height =match_parent> < ImageView的
机器人:layout_width =100dp
机器人:layout_height =WRAP_CONTENT
机器人:填充=10dp
机器人:ID =@ + ID / ivProduct
机器人:SRC =@绘制/信息noImage/>< / LinearLayout中>
code:
LinearLayoutManager的layoutManager
=新LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,FALSE);
RecyclerView productImageList =(RecyclerView)view.findViewById(R.id.rvProducts);
productImageList.setLayoutManager(的layoutManager);
GalleryRecyclerAdapter适配器=新GalleryRecyclerAdapter(图像);
productImageList.setAdapter(适配器);
一sollution是设置每个孩子的宽度programmaticaly像
view.getLayoutParams()宽= getScreenWidth()/ VIEWS_COUNT_TO_DISPLAY。
和屏幕尺寸是这样的:
DisplayMetrics指标=新DisplayMetrics();
。getWindowManager()getDefaultDisplay()getMetrics(指标).widthPixels。
I am trying to show exact (eg. 3 items) in RecyclerView. Our web application shows like this:
If I move items:
and release the mouse, it automatically comes to this:
In Android, I am showing images using RecyclerView:
How to show exactly 3 items in the visible area of RecyclerView? How to avoid to show "half" items? Is this possible?
RecyclerView:
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="130dp"
android:id="@+id/rvProducts" />
One item in recycler view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:id="@+id/ivProduct"
android:src="@drawable/noimage"/>
</LinearLayout>
Code:
LinearLayoutManager layoutManager
= new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
RecyclerView productImageList = (RecyclerView) view.findViewById(R.id.rvProducts);
productImageList.setLayoutManager(layoutManager);
GalleryRecyclerAdapter adapter = new GalleryRecyclerAdapter(images);
productImageList.setAdapter(adapter);
One sollution is to set width of each child programmaticaly like
view.getLayoutParams().width = getScreenWidth() / VIEWS_COUNT_TO_DISPLAY;
And the screen size like this:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics).widthPixels;
这篇关于如何显示RecyclerView项目的确切数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!