How do you layout a form that scrolls in Android SDK? -
i need have user form larger screen. layout consists of fixed "title area", form (in scrollview possibly) , button on bottom. have created 3 layouts , middle layout scrollview vertically-oriented linearlayout. unfortunately, form pushes buttons off screen?!
is there simple example this?
i suppose can use listview, think scrollview easier manage. here layout ...
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <!-- title area on top --> <linearlayout android:id="@+id/layout_form" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" > <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" > <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="0dip" android:layout_marginbottom="0dip" android:paddingtop="20dip" android:paddingbottom="20dip" android:paddingleft="5dip" android:paddingright="10dip" android:src="@drawable/logo" android:layout_gravity="center" android:layout_weight="1" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="2" android:layout_margintop="0dip" android:layout_marginbottom="0dip" android:layout_marginleft="4dip" android:layout_marginright="4dip" android:text="@string/title_create" /> </linearlayout> <!-- form entry on top --> <scrollview android:layout_width="fill_parent" android:layout_height="wrap_content" android:fillviewport="true" android:clipchildren="true" > <linearlayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" > <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginleft="8dip" android:layout_marginright="8dip" android:text="@string/label_field_one" /> <edittext android:id="@+id/edit_field_one" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleline="true" android:layout_marginleft="10dip" android:layout_marginright="10dip" android:hint="@string/hint_field_one" /> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginleft="8dip" android:layout_marginright="8dip" android:text="@string/label_field_two" /> <edittext android:id="@+id/edit_field_two" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleline="true" android:layout_marginleft="10dip" android:layout_marginright="10dip" android:hint="@string/hint_field_two" /> <!-- repeat label-text , edit-text until done ... --> </linearlayout> </scrollview> <!-- "spring" between form , wizard buttons. --> <linearlayout android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" /> <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="left" android:layout_weight="2" > <button android:id="@+id/btn_submit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_weight="1" android:text="@string/button_submit" /> </linearlayout> </linearlayout> </linearlayout>
if understand correctly, that's brought pretty commonly - having fixed header , footer, , fill middle whatever (in case, scrollview). you're looking for? if so, you'll want try below:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <linearlayout android:id="@+id/header" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparenttop="true" > //.....stuff here </linearlayout> <linearlayout android:id="@+id/footer" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" > //.....stuff here </linearlayout> <scrollview android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@id/footer" android:layout_below="@id/header" > //......stuff here </scrollview> </relativelayout>
basically, define header, give fixed height (wrap_content in case), , set align top of parent (the relativelayout). then, same footer, aligning bottom of parent. substitute button linearlayout footer, situation, or can place button inside linearlayout. it's faster inflate layout without linearlayout. anyway, next, define form, scrolling area. set height fill_parent, , tell above footer, , below header. cause take remaining space between header , footer.
Comments
Post a Comment