列表视图 - 页脚在屏幕的底部视图、屏幕、列表

2023-09-06 02:16:46 作者:爱情,就像慢性毒药侵蚀饿

我与 listview.addFooterView(footerView)增加了一个页脚一个ListView;

如预期除外在一种情况下的所有作品:当我的ListView的项目不能填满整个屏幕,我想在脚注中,而不是在中间的是在屏幕的底部。有没有一种方法可以轻松地做到这一点?或者我应该改变我的布局?

All works as expected excepted in one case: when my listview's items doesn't fill the whole screen, I would like the footer to be at the bottom of the screen, instead of being in the middle. Is there a way to do this easily? Or should I change my layout?

感谢

编辑:这可能有助于(这是我想要的)

that might help (this is what I want)

推荐答案

如果你希望它永远是在屏幕,底部无论多久你的的ListView ,则摆脱 listview.addFooterView(footerView)的; 和使用 RelativeLayout的。给你的 ListView`属性

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.

修改

看完评论之后可能会奏效。有可能是一个更简单的方法,但你可以不喜欢

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 将是一个自定义的布局,你将创建我以上所提到的属性。这应该设置为可见如果项目不超过可容纳在屏幕上。如果他们更不能容纳那么你敷在的ListView 因为你现在的页脚视图。这可能不是,但我想到的最好的办法了的第一件事。设置之前,你会运行此code中的适配器

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.

 
精彩推荐
图片推荐