在我的应用程序中,我希望数据显示在列表中。布局将交错。为此我使用RecyclerView与StaggeredGridLayout,但我仍然没有得到所需的效果。请帮助我实现这一目标。
列表行
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="05dp"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:paddingBottom="10dp"
android:paddingLeft="30dp"
android:background="#861e1e"
android:paddingRight="30dp"
android:paddingTop="10dp"
android:text="New Button" />
</RelativeLayout>
ListActivity
private RecyclerView recyclerView;
private List<String> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_with_pager);
inflateViews();
}
@Override
protected void inflateViews() {
list = new ArrayList<>();
recyclerView = (RecyclerView) findViewById(R.id.rv_lvp_main);
//GridLayoutManager gridLayoutManager=new GridLayoutManager(this,3);
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(5, StaggeredGridLayoutManager.VERTICAL);
layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
recyclerView.setLayoutManager(layoutManager);
//recyclerView.setLayoutManager(gridLayoutManager);
//recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(new StaggeredAdapter(this, getList()));
}