问题描述
这是它如何能已经完成previously在的ListView
类,用一个例子的分和 dividerHeight 的参数:
This is an example of how it could have been done previously in the ListView
class, using the divider and dividerHeight parameters:
<ListView
android:id="@+id/activity_home_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@android:color/transparent"
android:dividerHeight="8dp"/>
不过,我不认为这样的可能性,在 RecyclerView
类。
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_home_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
在这种情况下,它是确定确定利润和/或直接添加自定义分隔视图到一个列表项的布局还是有更好的方式来实现我的目标?
In that case, is it ok to define margins and/or add a custom divider view directly into a list item's layout or is there a better way to achieve my goal?
推荐答案
可能我直接请你注意由Alex符Github上这个特殊的文件:https://gist.github.com/alexfu/0f464fc3742f134ccd1e
Might I direct your attention to this particular file on Github by Alex Fu:https://gist.github.com/alexfu/0f464fc3742f134ccd1e
这是DividerItemDecoration.java示例文件从支持演示直线拉升。(https://plus.google.com/103498612790395592106/posts/VVEB3m7NkSS)
It's the DividerItemDecoration.java example file "pulled straight from the support demos".(https://plus.google.com/103498612790395592106/posts/VVEB3m7NkSS)
我能在我的项目导入此文件后能得到很好的分隔线并将其添加为一个项目装修到回收视图。
I was able to get divider lines nicely after importing this file in my project and add it as an item decoration to the recycler view.
下面是我如何onCreateView看起来像含Recyclerview我的片段:
Here's how my onCreateView look like in my fragment containing the Recyclerview:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_recycler_view, container, false);
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.my_recycler_view);
mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
return rootView;
}
我敢肯定,更多的造型可以做到的,但它是一个起点。 :)
I'm sure additional styling can be done, but it's a starting point. :)
这篇关于如何增加项目之间的分隔和空格RecyclerView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!