Android: Button at the end of listview OR bottom of screen

妖精的绣舞 提交于 2019-12-22 08:46:51

问题


I have a requirement for my android application that a button is at the bottom end of the list. That is done on purpose so users have to scroll trough the entire list (and possibly see more answers). Therefore I added the button as a listview footer.

This all works fine but in some cases the list is too short (only 3-4 items in it) so the button will end up about midway of the screen. What I would like is that the button is at the end of the listview (so if enough items in the list, the user can only see the button when he scrolls down) but when the listview only contains a few items the button will fix itself to the bottom of the screen.

To give the idea I want:

onCreate() {
   if (button.getyposition() > screen.getyposition()) { // example methodnames!
      // Button at the bottom of the listview (many items)
   }
   else {
      // Button at the bottom of the screen (few items in listview)
   }
}

The point is, I don't know if it's possible and where to start. Could anyone give me some directions where to look or even better a piece of sample code? Thanks in advance!

EDIT:

I added a picture to clarify my problem. I hope this makes more sense!

Picture showing the button halfway on the screen http://niles11.dyndns.org/example.png

As you can see, it looks quite strange with the button halfway on the screen. I want the button to be at the bottom of the screen BUT (!) when the listview contains more items I want it to appear at the bottom of the listview (so at first, be off screen)

Hope this picture helps!


回答1:


I understand you Issue. I have an ideal : you should inflate last item(position = array.size) as a button instead of normal view item.




回答2:


if i am not wrong you want your listview on the whole screen with a button below. make listview's height match_parent and android:layout_margingBottom="somedp" and for button marginTop="-somedp" somedp shoulb same on both places...




回答3:


Set the ListView height to fill_parent and add a Button as the footer using addFooterView()

If you have the requirement that you only show the Button when the List is scrolled to the end, then you can look at this post and use the logic to show/hide the footer view (ie, set View.GONE on the footer to hide it, and View.VISIBLE to show it)



来源:https://stackoverflow.com/questions/10910574/android-button-at-the-end-of-listview-or-bottom-of-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!