我的交错视图是这样实现的MyApp 但它应该看起来像这个演示 而且我无法更改行和列应用程序以空白 Activity 运行。
MainActivity.java
package com.techshiv.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private StaggeredGridLayoutManager staggeredGridLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, 2);
recyclerView.setLayoutManager(staggeredGridLayoutManager);
List<ItemObjects> staggerdedList = getListItemData();
SolventRecyclerViewAdapter rcAdapter = new SolventRecyclerViewAdapter(MainActivity.this , staggerdedList);
recyclerView.setAdapter(rcAdapter);
}
private List<ItemObjects> getListItemData(){
List<ItemObjects> listViewItems = new ArrayList<ItemObjects>();
listViewItems.add(new ItemObjects("Alkane", R.drawable.one));
listViewItems.add(new ItemObjects("Ethane", R.drawable.two));
listViewItems.add(new ItemObjects("Alkyne", R.drawable.three));
listViewItems.add(new ItemObjects("Benzene", R.drawable.four));
listViewItems.add(new ItemObjects("Amide", R.drawable.one));
listViewItems.add(new ItemObjects("Amino Acid", R.drawable.two));
listViewItems.add(new ItemObjects("Phenol", R.drawable.three));
listViewItems.add(new ItemObjects("Carbonxylic", R.drawable.four));
listViewItems.add(new ItemObjects("Nitril", R.drawable.one));
listViewItems.add(new ItemObjects("Ether", R.drawable.two));
listViewItems.add(new ItemObjects("Ester", R.drawable.three));
listViewItems.add(new ItemObjects("Alcohol", R.drawable.four));
listViewItems.add(new ItemObjects("Ether", R.drawable.five));
listViewItems.add(new ItemObjects("Ester", R.drawable.three));
listViewItems.add(new ItemObjects("Alcohol", R.drawable.four));
return listViewItems;
}
}