如何添加空格到ListView的结束? [英] How can I add blank space to the end of a ListView?

查看:199
本文介绍了如何添加空格到ListView的结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些元素在的ListView 是在屏幕上滚过。

我想那里是在视图的最后空白。即,用户应该能够滚过的最后一个元素,使得最后一个元素是在视口的中间

我可以用一个 OverScroller 的,但我认为只会使视图有就像一个有弹性的效果经常看到在iPhone上。

有什么我可能忽略了?

在滚动到最钮屏幕应该是这个样子:

解决方案
  1. 充气您所选择的任何布局(这可能是一个XML和ImageView的,没有绘制,并与设定的高度和宽度您所选择的)
  2. 测量屏幕高度,创造新的LayoutParams并设置它的高度的1/2,屏幕高度的
  3. 设置新的布局PARAMS您放大视图
  4. 使用ListView的<一个href="http://developer.android.com/reference/android/widget/ListView.html#addFooterView%28android.view.View%29"><$c$c>addFooterView()方法是查看添加到列表的底部(也有一个 addHeaderView()

code来衡量屏幕高度

 窗口管理WM =(窗口管理器)context.getSystemService(Context.WINDOW_SERVICE);
 显示显示= wm.getDefaultDisplay();
 INT screenHeight = display.getHeight();
 

code设置半屏高度:

 视图布局= inflater.inflate(R.layout.mylistviewfooter,集装箱,假);
 ViewGroup.LayoutParams LP = layout.getLayoutParams();
 lp.height = screenHeight / 2;
 layout.setLayoutParams(LP);
 myListView.addFooterView(布局);
 

这是题外话: 当您添加一个页脚或页眉以任何列表视图,它具有增加适配器之前完成。另外,如果你需要做这个之后,让您的适配器类,你需要知道通过 getAdapter调用列表视图的适配器()将返回<一个实例href="http://developer.android.com/reference/android/widget/HeaderViewListAdapter.html">HeaderViewListAdapter在其中,你将需要调用它的<一个href="http://developer.android.com/reference/android/widget/HeaderViewListAdapter.html#getWrappedAdapter%28%29">getWrappedAdapter方法 事情是这样的:

  MyAdapterClassInstance myAdapter =(MyAdapterClassInstance)((HeaderViewListAdapter)myListView.getAdapter())getWrappedAdapter()。
 

I have a number of elements in a ListView that scroll off the screen.

I would like there to be blank space at the end of the View. That is, the user should be able to scroll past the last element such that the last element is in the middle of the viewport.

I could use an OverScroller, but I think that would only enable the View to have a bouncy effect like one often sees on the iPhone.

Is there something I might have overlooked?

The scrolled-to-the-botton screen should look something like this:

解决方案

  1. Inflate any layout of your choice (this could be an XML of and ImageView with no drawable and with set height and width of your choice)
  2. Measure the screen height and create new LayoutParams and set the height of it to 1/2 of the screen height
  3. Set the new layout params on your inflated view
  4. Use the ListView's addFooterView() method to add that view to the bottom of your list (there is also an addHeaderView())

Code to measure screen height

 WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
 Display display = wm.getDefaultDisplay();
 int screenHeight = display.getHeight();

Code to set half screen height:

 View layout = inflater.inflate(R.layout.mylistviewfooter, container, false);
 ViewGroup.LayoutParams lp = layout.getLayoutParams();
 lp.height = screenHeight/2;
 layout.setLayoutParams(lp);
 myListView.addFooterView(layout);

An Aside: When you add a footer or header view to any listview, it has to be done before adding the adapter. Also, if you need to get your adapter class after doing this you will need to know calling the listview's adapter by getAdapter() will return an instance of HeaderViewListAdapter in which you will need to call its getWrappedAdapter method Something like this :

 MyAdapterClassInstance myAdapter = (MyAdapterClassInstance) ((HeaderViewListAdapter) myListView.getAdapter()).getWrappedAdapter();

这篇关于如何添加空格到ListView的结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆