コード例 #1
0
 private void changeListVisualization(MenuItem menuItem) {
   if (isListView) {
     staggeredGridLayoutManager.setSpanCount(2);
     menuItem.setIcon(R.drawable.ic_action_list);
     menuItem.setTitle(R.string.menu_show_as_list);
     isListView = false;
   } else {
     staggeredGridLayoutManager.setSpanCount(1);
     menuItem.setIcon(R.drawable.ic_action_grid);
     menuItem.setTitle(R.string.menu_show_as_grid);
     isListView = true;
   }
 }
コード例 #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // For larger devices (like tablets), it creates more columns.
    int columnsNumber = getActivity().getResources().getInteger(R.integer.restaurant_columns);
    if (mStaggeredGridLayoutManager == null) {
      mStaggeredGridLayoutManager =
          new StaggeredGridLayoutManager(columnsNumber, StaggeredGridLayoutManager.VERTICAL);
    } else {
      mStaggeredGridLayoutManager.setSpanCount(columnsNumber);
    }
  }