Android: button at the end of the list or at the bottom of the screen

I have a requirement for my Android application that the button is at the bottom of the list. This is done specifically so that users can scroll through the entire list (and possibly see more answers). So I added a button as a list footer.

All this works fine, but in some cases the list is too short (only 3-4 items), so the button will be displayed approximately in the middle of the screen. I would like the button to be at the end of the list (therefore, if there are enough elements in the list, the user can only see the button when scrolling down), but when the list contains only a few elements, the button will fix itself at the bottom of the screen.

To give an 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 fact is, I don’t know if and where to start. Can someone give me some guidance on where to look for or even better sample code? Thanks in advance!

EDIT:

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

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

As you can see, this looks pretty weird with a button half on the screen. I want the button to be at the bottom of the BUT screen (!), When the list contains more elements I want them to appear at the bottom of the list (so turn off the screen first)

Hope this picture helps!

+4
source share
3 answers

I understand you, problem. I have an ideal: you should inflate last element (position = array.size) as a button instead of the usual view element.

0
source

If I'm not mistaken, you want your list to be displayed in full screen using the button below. make listview height match_parent and android: layout_margingBottom = "somedp" and for the button marginTop = "- somedp" somedp shoulb is the same in both places ...

0
source

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

If you have a requirement that you only show Button when the list scrolls to the end, you can watch this post and use the logic to show / hide the footer view (i.e. set View.GONE on the footer to hide it, and View.VISIBLE to show it)

0
source

Source: https://habr.com/ru/post/1416315/


All Articles