Android RecyclerView not showing the right xml -
i'm trying use recyclerview show horizontal list of contacts. spend hours find error , don't understand why keep happening. application tinder-like.
my row item :
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="80dp" android:layout_height="80dp" xmlns:tool="http://schemas.android.com/tools" android:background="@color/white" android:layout_margin="8dp"> <textview android:id="@+id/tv_conversation_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_alignparentbottom="true" android:textalignment="center" android:textcolor="@color/black" android:textsize="4pt" tool:text="name name"/> <imageview android:id="@+id/iv_conversation_avatar" android:layout_width="match_parent" android:layout_height="match_parent" android:scaletype="centercrop" android:layout_margin="2dp" android:src="@drawable/photo1" android:layout_above="@id/tv_conversation_name"/> </relativelayout>
i did layout 1 in other fragment
my adapter :
public class conversationadapter extends recyclerview.adapter<conversationadapter.conversationviewholder>{ private list<conversation> conversationlist = new arraylist<>(); public class conversationviewholder extends recyclerview.viewholder { public textview title; public imageview avatar; conversationviewholder(view view) { super(view); title = (textview) view.findviewbyid(r.id.tv_conversation_name); avatar = (imageview) view.findviewbyid(r.id.iv_conversation_avatar); } } public conversationadapter(list<conversation> conversationlist) { this.conversationlist = conversationlist; } @override public conversationviewholder oncreateviewholder(viewgroup parent, int viewtype) { view itemview = layoutinflater.from(parent.getcontext()).inflate(r.layout.item_conversation, parent, false); return new conversationviewholder(itemview); } @override public void onbindviewholder(conversationviewholder holder, int position) { conversation conversation = conversationlist.get(position); holder.title.settext(conversation.getname()); byte[] decodedbytearray = android.util.base64.decode(conversation.getimage(), base64.default); holder.avatar.setimagebitmap(bitmapfactory.decodebytearray(decodedbytearray, 0, decodedbytearray.length)); } @override public int getitemcount() { return conversationlist.size(); } }
how configure recyclerview :
conversationadapter = new conversationadapter(conversationlist); recyclerview.layoutmanager mlayoutmanagerhorizontal = new linearlayoutmanager(getactivity().getapplicationcontext(),linearlayoutmanager.horizontal, false); rvconversation.setlayoutmanager(mlayoutmanagerhorizontal); rvconversation.setitemanimator(new defaultitemanimator()); rvconversation.setadapter(conversationadapter);
it looks width , height of relativelayout in row item file 80dp, don't think want here. try setting these values "match_parent", this:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:tool="http://schemas.android.com/tools" android:background="@color/white" android:layout_margin="8dp">
or use "wrap_content", depending on trying achieve.
Comments
Post a Comment