Search in sources :

Example 1 with GreedoSpacingItemDecoration

use of com.fivehundredpx.greedolayout.GreedoSpacingItemDecoration in project greedo-layout-for-android by 500px.

the class SampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    PhotosAdapter photosAdapter = new PhotosAdapter(this);
    final GreedoLayoutManager layoutManager = new GreedoLayoutManager(photosAdapter);
    layoutManager.setMaxRowHeight(MeasUtils.dpToPx(150, this));
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(photosAdapter);
    int spacing = MeasUtils.dpToPx(4, this);
    recyclerView.addItemDecoration(new GreedoSpacingItemDecoration(spacing));
    findViewById(R.id.toggle_fixed_height).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            layoutManager.setFixedHeight(((ToggleButton) view).isChecked());
            layoutManager.requestLayout();
        }
    });
}
Also used : GreedoLayoutManager(com.fivehundredpx.greedolayout.GreedoLayoutManager) ToggleButton(android.widget.ToggleButton) RecyclerView(android.support.v7.widget.RecyclerView) GreedoSpacingItemDecoration(com.fivehundredpx.greedolayout.GreedoSpacingItemDecoration) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ToggleButton (android.widget.ToggleButton)1 GreedoLayoutManager (com.fivehundredpx.greedolayout.GreedoLayoutManager)1 GreedoSpacingItemDecoration (com.fivehundredpx.greedolayout.GreedoSpacingItemDecoration)1