Listview - Footer at the bottom of screen

前端 未结 4 525

I have a ListView with a footer added with listview.addFooterView(footerView);

All works as expected excepted in one case: when my listview\'s items doe

4条回答
  •  感情败类
    2020-12-17 16:28

    If you want it to always be at the bottom of the screen, no matter how long your ListView is, then get rid of listview.addFooterView(footerView); and use a RelativeLayout. Give yourListView` the property

     android:layout_alignParentTop="true"
    

    and give the property to your footer

     android:layout_alignParentBottom="true"
    

    If this doesn't solve your problem then please be a little more specific about what you want and provide a picture of what you want if possible.

    Edit

    After reading the comments this might work. There might be an easier way but you could do something like

         listView.post(new Runnable()
         {       
             public void run()
            {
                int numItemsVisible = listView.getLastVisiblePosition() - 
                listView.getFirstVisiblePosition();
                if (itemsAdapter.getCount() - 1 > numItemsVisible)
                {   
                     // set your footer on the ListView
                }
                else
                {
                     footerView.setVisibility(View.VISIBLE);
                }
             }
    

    footerView would be a custom layout that you would create with the properties I referenced above. This should set that to visible if the items aren't more than can fit on the screen. If they are more than can fit then you apply the footer view on the ListView as you are now. This might not be the best way but its the first thing that comes to mind. You would run this code just before you set the Adapter.

提交回复
热议问题