android - How can I set the horizontal spacing in HorizontalGridView? -
whole fragment layout: fragment layout
i want separate views there 15dp of horizontal break between cards, looks : overlapped views
i've tried adding android:horizontalspacing (like in regular gridview) attribute xml, nothing happened. using childrenoffsethorizontal layoutmanager didn't give results expected.
here's code of fragment:
public class tvdetailsfragment extends fragment { private horizontalgridview gridview; private seasonslistadapter seasonslistadapter; public tvdetailsfragment(){ } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // arguments showdetailsactivity. bundle args = getarguments(); view rootview = inflater.inflate(r.layout.fragment_tv_details, container, false); gridview = (horizontalgridview)rootview. findviewbyid(r.id.tv_details_seasons_gridview); gridview.setlayoutmanager(new linearlayoutmanager(getactivity(), linearlayoutmanager.horizontal, false)); gridview.getlayoutmanager().set fetchtvdetailsbyid fetchdetails = new fetchtvdetailsbyid(getcontext()); fetchdetails.execute(args.getstring("show_id")); return rootview; } public void populateview(tvclass tvdetails) { activity mactivity = getactivity(); imageview imageview = (imageview)mactivity.findviewbyid(r.id.tv_details_imageview); picasso.with(mactivity).load(tvdetails.getshowposterlink()) .fit() .into(imageview); textview titleview = (textview) mactivity.findviewbyid(r.id.tv_details_title_textview); titleview.settext( html.fromhtml("<b>" + "original title: " + "</b> <br>" + tvdetails.getshoworiginaltitle())); textview dateview = (textview) mactivity.findviewbyid(r.id.tv_details_date_textview); dateview.settext(html.fromhtml("<b>" + "release date: " + "</b> <br>" + tvdetails.getshowreleasedate())); textview voteview = (textview) mactivity.findviewbyid(r.id.tv_details_vote_textview); voteview.settext(html.fromhtml("<b>" + "vote average: " + "</b> <br>" + double.tostring(tvdetails.getshowvoteaverage()) + "/10")); textview overviewview = (textview) mactivity.findviewbyid(r.id.tv_details_overview_textview); overviewview.settext(tvdetails.getshowoverview()); // make cards visible after loading content. cardview postercard = (cardview)mactivity.findviewbyid(r.id.tv_details_poster_card); postercard.setvisibility(view.visible); cardview infocard = (cardview)mactivity.findviewbyid(r.id.tv_details_info_card); infocard.setvisibility(view.visible); cardview detailscard = (cardview)mactivity.findviewbyid(r.id.tv_details_overview_card); detailscard.setvisibility(view.visible); arraylist<showthumbnail> seasonthumbnails = tvdetails.getseasonsthumbnails(); seasonslistadapter = new seasonslistadapter(getactivity(), seasonthumbnails); gridview.setadapter(seasonslistadapter); // dismiss loading panel. relativelayout loadingpanel = (relativelayout)mactivity.findviewbyid(r.id.tv_details_loading_panel); loadingpanel.setvisibility(view.gone); }
fragment_tv_details.xml:
<scrollview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margintop="?android:attr/actionbarsize"> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/content_tv_details" android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustviewbounds="true" android:padding="20dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.example.mordowiciel.filmapp.activity.showdetailsactivity"> <relativelayout android:id="@+id/tv_details_loading_panel" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:gravity="center"> <progressbar android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminate="true" /> </relativelayout> <!-- poster of movie --> <android.support.v7.widget.cardview android:id="@+id/tv_details_poster_card" android:layout_width="150dp" android:layout_height="200dp" android:visibility="invisible" card_view:cardcornerradius="4dp"> <imageview android:id="@+id/tv_details_imageview" android:layout_width="130dp" android:layout_height="180dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="10dp" /> </android.support.v7.widget.cardview> <!-- linear layout info on right. root linear layout crucial implementing maxheight attribute cardview. (180dp.) if content in cardview >180dp in height, view starting act scrollable.--> <linearlayout android:layout_width="wrap_content" android:layout_height="180dp" android:layout_alignparentright="true" android:layout_marginleft="20dp" android:layout_margintop="20dp" android:layout_torightof="@+id/tv_details_poster_card"> <android.support.v7.widget.cardview android:id="@+id/tv_details_info_card" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="invisible"> <scrollview android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <textview android:id="@+id/tv_details_title_textview" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" /> <textview android:id="@+id/tv_details_vote_textview" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" /> <textview android:id="@+id/tv_details_date_textview" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" /> </linearlayout> </scrollview> </android.support.v7.widget.cardview> </linearlayout> <android.support.v7.widget.cardview android:id="@+id/tv_details_overview_card" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/tv_details_poster_card" android:layout_margintop="20dp" android:visibility="invisible"> <textview android:id="@+id/tv_details_overview_textview" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" /> </android.support.v7.widget.cardview> <android.support.v17.leanback.widget.horizontalgridview android:id="@+id/tv_details_seasons_gridview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/tv_details_overview_card" android:layout_margintop="20dp" android:gravity="center"> </android.support.v17.leanback.widget.horizontalgridview> </relativelayout>
image_item.xml:
<android.support.v7.widget.cardview xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_gravity="center" android:layout_width="150dp" android:layout_height="230dp" card_view:cardcornerradius="4dp"> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingtop="10dp" android:paddingleft="10dp" android:paddingright="10dp"> <imageview android:id="@+id/image_item_imageview" android:layout_width="130dp" android:layout_height="180dp" android:layout_centerhorizontal="true" android:scaletype="centercrop" /> <textview android:id="@+id/image_item_textview" android:layout_width="150dp" android:layout_height="wrap_content" android:layout_below="@id/image_item_imageview" android:layout_centerhorizontal="true" android:ellipsize="end" android:gravity="center" android:maxlines="2" android:text="beniz" android:layout_alignparentbottom="true" /> </relativelayout>
and custom recyclerview.adapter:
public class seasonslistadapter extends recyclerview.adapter<seasonslistadapter.seasonviewholder> { private arraylist<showthumbnail> showthumbnailslist; private context ctx; class seasonviewholder extends recyclerview.viewholder { protected imageview imageview; protected textview textview; public seasonviewholder(view view) { super(view); this.imageview = (imageview) view.findviewbyid(r.id.image_item_imageview); this.textview = (textview) view.findviewbyid(r.id.image_item_textview); } } public seasonslistadapter(context ctx, arraylist<showthumbnail> showthumbnails) { this.showthumbnailslist = showthumbnails; this.ctx = ctx; } @override public seasonviewholder oncreateviewholder(viewgroup viewgroup, int i) { view view = layoutinflater.from(viewgroup.getcontext()).inflate(r.layout.image_item, null); seasonviewholder seasonviewholder = new seasonviewholder(view); return seasonviewholder; } @override public void onbindviewholder (seasonviewholder seasonviewholder, int i) { showthumbnail showthumbnailitem = showthumbnailslist.get(i); picasso.with(ctx).load(showthumbnailitem.getshowposterlink()) .fit() .into(seasonviewholder.imageview); seasonviewholder.textview.settext(showthumbnailitem.getshowtitle()); } @override public int getitemcount() { return (null != showthumbnailslist ? showthumbnailslist.size() : 0); }
your xml wrong.
add margin cards. not images. give required spacing between cards!
<android.support.v7.widget.cardview android:id="@+id/tv_details_poster_card" android:layout_width="150dp" android:layout_height="200dp" android:visibility="invisible" card_view:cardcornerradius="4dp" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:layout_margintop="10dp"> <imageview android:id="@+id/tv_details_imageview" android:layout_width="130dp" android:layout_height="180dp" /> </android.support.v7.widget.cardview>
Comments
Post a Comment