android - align a text view below a scroll view -
i using following layout hierarchy:
linearlayout
....linearlayout
....... textview
....relativelayout
..........textview
....scrollview
....place want fixed bottom text view
i read on - needed enter following attribute scrollview:
android:layout_weight="1"
this ensured bottom text view ( intended fixed ) shown.
so while works - problem - if have less content in scroll view ( content populated dynamically ) - bottom text view climbs leaving making real ugly.
what want have bottom view fixed - irrrespective of content of scroll view.
here layout :
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <linearlayout style="@style/examtitlebar" > <imagebutton android:id="@+id/imgprevious" style="@style/titlebaraction" android:contentdescription="@string/description_home" android:onclick="previous" android:src="@drawable/previous" /> <imagebutton android:id="@+id/imghome" style="@style/titlebaraction" android:contentdescription="@string/description_home" android:onclick="onclickhome" android:src="@drawable/title_home" /> <imageview style="@style/titlebarseparator" /> <textview style="@style/examtitlebartext" /> <imageview style="@style/titlebarseparator" /> <imagebutton android:id="@+id/imgnext" style="@style/titlebaraction" android:contentdescription="@string/description_search" android:onclick="next" android:src="@drawable/next" /> <imagebutton android:id="@+id/imgreport" style="@style/titlebaraction" android:contentdescription="@string/description_search" android:onclick="reportdisplay" android:src="@drawable/setttings" /> </linearlayout> <relativelayout style="@style/messagebar" > <textview android:id="@+id/msgbar" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <textview android:id="@+id/questioncount" android:layout_alignparentleft="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="7dip" /> <textview android:id="@+id/timeleft" android:layout_alignparentright="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </relativelayout> <scrollview android:id="@+id/scrollview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_alignparentright="true" android:layout_below="@+id/questionlabel" android:layout_weight="1"> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <textview android:id="@+id/question" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="7dip" android:layout_marginright="5dip" android:layout_margintop="5dip" android:layout_marginbottom="5dip" android:fontfamily="helvetica" android:textsize="17sp"/> <linearlayout style="@style/separatorbartop" > <textview android:id="@+id/separatorbar1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </linearlayout> <radiogroup android:id="@+id/radiogroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:fontfamily="helvetica" android:textsize="17sp" > <radiobutton style="@style/radiobuttons" android:id="@+id/option1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="option1" /> <radiobutton style="@style/radiobuttons" android:id="@+id/option2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="option2" /> <radiobutton style="@style/radiobuttons" android:id="@+id/option3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="option3" /> <radiobutton style="@style/radiobuttons" android:id="@+id/option4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="option4" /> </radiogroup> <linearlayout style="@style/separatorbarbottom" > <textview android:id="@+id/separatorbar2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </linearlayout> <!-- image view goes here start --> <imageview android:id="@+id/imageview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:src="@drawable/velocity_graph" /> <!-- image view goes here end --> <textview style="@style/answerdetails" android:id="@+id/answerdetails" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="5dip" android:layout_marginright="7dip" android:layout_margintop="5dip" android:fontfamily="helvetica" android:textsize="17sp"/> <!-- separator bar image start <linearlayout style="@style/separatorbarbottom" > <textview android:id="@+id/separatorimagebar" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </linearlayout> separator for image end --> </linearlayout> </scrollview> <!-- desired fixed bottom view --> <linearlayout android:layout_gravity="bottom" style="@style/examtitlebar" > <textview style="@style/examtitlebartext" /> </linearlayout> <!-- moiraine end --> </linearlayout>
set scrollview height fixed size. eg. android:layout_height="240dp"
. 1 relativelayout components enough, use alignbottom. nesting layouts slows down app performance see dev docs:http://developer.android.com/training/improving-layouts/optimizing-layout.html)
Comments
Post a Comment