android - RecyclerView item width layout_width=“match_parent” does not match parent -
i'm using recyclerview , i'm trying make width item of recyclerview match_parent since i'm using
linearlayoutmanager.horizontal
<android.support.v7.widget.recyclerview android:id="@+id/listoffershits" android:layout_width="match_parent" android:layout_height="match_parent" />
custom_layout.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.cardview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/card_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:layout_weight="1" android:layout_margin="2dp" card_view:cardcornerradius="2dp"> <imageview android:id="@+id/offerimage" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/item_selector" android:scaletype="fitxy" android:src="@drawable/offer" /> </android.support.v7.widget.cardview>
layoutmanager
linearlayoutmanager linearlayoutmanager = new linearlayoutmanager(getactivity(),linearlayoutmanager.horizontal, false); listoffershits.setlayoutmanager(linearlayoutmanager);
viewholder
view view= layoutinflater.from(parent.getcontext()) .inflate(r.layout.custom_layout, parent, false); viewoffersholder viewholder=new viewoffersholder(view); return viewholder;
i fixed problem:
1- screen size (width).
2- make viewholder width same screen size.
below code if 1 need it.
windowmanager windowmanager = (windowmanager)context.getsystemservice(context.window_service); int width = windowmanager.getdefaultdisplay().getwidth(); int height = windowmanager.getdefaultdisplay().getheight(); view.setlayoutparams(new recyclerview.layoutparams(width, recyclerview.layoutparams.match_parent));
Comments
Post a Comment