java - Make Listview to Occupy Whole Screen -
i have listview want fill whole screen,there 4 items in listview. leaves empty space below after 4 items filled.you can see in screenshot. leaves blank space. want whole screen covered.
i have this:
here source code
mainactivity.java.
public class mainactivity extends activity { listview resultpane; list<taskinfo> list; customadapter adapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); resultpane = (listview) findviewbyid(r.id.mylist); list = new arraylist<taskinfo>(); resources res = getresources(); // resource handle drawable drawable = res.getdrawable(r.drawable.browse_home); list.add(new taskinfo("browse", drawable)); drawable = res.getdrawable(r.drawable.jewelry); list.add(new taskinfo("whats new", drawable)); drawable = res.getdrawable(r.drawable.show); list.add(new taskinfo("upcoming show", drawable)); drawable = res.getdrawable(r.drawable.contact); list.add(new taskinfo("contact us", drawable)); adapter = new customadapter(this, list); resultpane.setadapter(adapter); } }
customadapter.java
public class customadapter extends baseadapter { private context context; private list<taskinfo> list; public customadapter(context context, list<taskinfo> list) { this.context = context; this.list = list; } public view getview(int index, view view, final viewgroup parent) { if (view == null) { layoutinflater inflater = layoutinflater.from(parent.getcontext()); view = inflater.inflate(r.layout.single_list_item, parent, false); } taskinfo t = list.get(index); relativelayout l = (relativelayout) view .findviewbyid(r.id.testrelative); l.setbackgrounddrawable(t.getimage()); textview textview = (textview) view.findviewbyid(r.id.title); textview.settext(t.getname()); return view; } }
single_list_item.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/testrelative" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/browse_home" android:orientation="horizontal" android:padding="5dip" > <!-- listrow left sied thumbnail image --> <linearlayout android:id="@+id/thumbnail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_marginright="5dip" android:padding="3dip" > </linearlayout> <textview android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_centervertical="true" android:layout_marginright="16dp" android:text="" android:textcolor="#040404" android:textsize="15dip" android:textstyle="bold" android:typeface="sans" /> </relativelayout>
activity_main.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <linearlayout android:layout_width="match_parent" android:layout_height="45sp" android:id="@+id/llayout" android:background="@drawable/navbar" android:padding="3sp" > <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center_horizontal" android:layout_weight="1" android:gravity="center_horizontal" android:text="golden stone" android:textcolor="@color/white" android:textsize="20sp" > </textview> </linearlayout> <listview android:id="@+id/mylist" android:layout_width="match_parent" android:layout_below="@id/llayout" android:layout_height="match_parent" > </listview> </relativelayout>
using listview
in such case strange , unnecessary. think constraints (like: if items overflow?) , use proper layout manager. vertical linearlayout
last item having non-zero layout weight.
listview
s make sense if need abstraction generates list items on-the-fly.
Comments
Post a Comment