Recyclerview 2 Columns With Cardview
I have a problem with my layout. I'm trying to do something like this: For now, i have a RecyclerView with a CardView inside it. in the CardView I have put an ImageView and a Text
Solution 1:
Extracted required info from the accepted answer in case URL becomes invalid in future and to save time.
GridLayoutManager is used to display the RecyclerView in Grid manner instead of list.
RecyclerView.LayoutManagermLayoutManager=newGridLayoutManager(this, 2);
recyclerView.setLayoutManager(mLayoutManager);
Kotlin version:
recyclerView.apply {
layoutManager = GridLayoutManager(this, 2)
}
Solution 2:
You can use this code simply
<android.support.v7.widget.RecyclerViewapp:layoutManager="android.support.v7.widget.GridLayoutManager"app:spanCount="2"/>
Solution 3:
With androidX libraries simply do:
<androidx.recyclerview.widget.RecyclerViewapp:layoutManager="androidx.recyclerview.widget.GridLayoutManager"app:spanCount="2"/>
Solution 4:
use "0dp"
in layout_width and layout_height
for putting views in it's position.
like this:
android:layout_width="0dp"
and use Guidelines in your xml
.
<ImageView
android:id="@+id/img_roomType"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:src="@drawable/img_room" />
<TextView
android:id="@+id/tvTypeName"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="20sp" />
this is NOT true code, u have to use Guidelines.
Post a Comment for "Recyclerview 2 Columns With Cardview"