Monday, March 7, 2011

Static buttons in listview

A common gui-layout strategy is having static buttons above or below a listview.

Consider the following layout:


This is accomplished by using a relative layout which includes the listview inside LinearLayout with bottom padding, then the buttons relative to parent.

Example layout xml of static buttons below listview. Key parameters are highlighted.
<RelativeLayout 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">

   <LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:layout_alignParentTop="true"
     android:paddingBottom="50sp">

      <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

      <TextView
        android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

   </LinearLayout>

   <Button
     android:layout_height="wrap_content"
     android:layout_width="124sp"
     android:layout_alignParentBottom="true"
     android:layout_alignParentLeft="true"/>

   <Button
     android:layout_width="124sp"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_centerHorizontal="true"/>

   <Button
     android:layout_width="124sp"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentRight="true"/>

</RelativeLayout>

No comments:

Post a Comment