Haryanto Haryanto - 5 months ago 13
Android Question

How to create a gridview like this in android xml

anyone, can help me how to create gridview like this? in android xml

http://i.stack.imgur.com/KCp73.jpg

Answer

use following code in xml

<android.support.v7.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="700dp"
        android:layout_margin="@dimen/text_margin"
        android:scrollbars="vertical"
     />

and then in your activity use like below,

recycler = (RecyclerView) findViewById(R.id.recycler);
RecyclerAdapter adapter = new RecyclerAdapter(list) ;
        RecyclerView.LayoutManager mLayoutManager = new    GridLayoutManager(getApplicationContext(),3);
        recycler.setLayoutManager(mLayoutManager);
        recycler.setItemAnimator(new DefaultItemAnimator());

        recycler.setAdapter(adapter);
Comments