交错视图行和列不会更改

时间:2016-01-31 15:41:25

标签: android staggered-gridview staggeredgridlayout

我的交错视图是这样实现的MyApp 但它应该看起来像Demo 我无法更改行和列如果我正在更改列,但如果我更改行超过1,那么我会得到invalidOrientation警告但应用程序运行空白活动。

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;
}
}

1 个答案:

答案 0 :(得分:0)

它没有行的参数,基本上你指定方向,将其视为行数 用这个:

StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);