Android ListView: Align last list item to top of screen -


i have listview's stackfrombottom xml attribute set true, when activity opens, last items in listview ones visible opposed top items, default.

however, want activity open last item in listview aligned top of screen. in other words, there should blank space below last item takes remaining space.

i've attempted adding footer view listview:

view footer = inflater.inflate(r.layout.empty_view, listview, false); viewgroup.layoutparams lp = footer.getlayoutparams(); lp.height = ???; footer.setlayoutparams(lp); listview.addfooterview(footer); 

the problem don't know during activity's oncreate function height assign blank footer view. need know height of last item in listview decide height make blank footer view, height of last listview item not fixed number.

how can height of last listview item? or perhaps there better way altogether?

i found simple solution problem: wrap listview in framelayout. apparently alignment handled differently other viewgroups.

this working code:

<framelayout         android:layout_width="match_parent"         android:layout_height="match_parent">         <listview             android:id="@+id/list"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:stackfrombottom="true" /> </framelayout> 

another approach remove android:stackfrombottom , scrolling manually simulate attribute's behaviour. save additional layer wouldn't recommend add complexity.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -