添加ListView的孩子去Horizo​​ntalScrollView [英] adding ListView children to a HorizontalScrollView

查看:193
本文介绍了添加ListView的孩子去Horizo​​ntalScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Horizo​​ntalScrollView,我加入了一堆的ListView作为它的孩子。我的XML文件看起来像下面这样。为简便起见,我会忽略掉某些属性。

i have a HorizontalScrollView, and i am adding a bunch of ListView as its children. my XML file looks something like the following. for brevity, i will omit some of the attributes.

<HorizontalScrollView>
 <LinearLayout>
  <ListView android:id="@+id/listView1" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
 </LinearLayout>
</HorizontalScrollView>

在我的Java code,然后我用数据填充ListView控件。如果只有1或2的记录,在ListView并不一直延伸到屏幕的底部。我看到什么似乎是一个透明背景。我要如何摆脱这一行为。

in my java code, i then populate the ListView with data. If there is only 1 or 2 records, the ListView does not extend all the way to the bottom of the screen. i see what seems to be a transparent background. how do i get rid of this behavior.

我也是用这个组件从 HTTP尝试-reid.co.uk/blog_post.php?id=62 。再次,我有同样的问题。

i also tried using this component from http://www.matt-reid.co.uk/blog_post.php?id=62. again, i have the same problem.

任何帮助是AP preciated。

any help is appreciated.

下面是XML文件。我已经简单地复制/粘贴控制code到我的包作为demo.fling8.Horizo​​ntalPager。

below is the XML file. i've simply copied/pasted the control code into my package as demo.fling8.HorizontalPager.

 <demo.fling8.HorizontalPager 
android:id="@+id/hp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

  <TextView
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:text= "Etiam et dui volutpat purus gravida consequat. Nullam sodales velit a nunc pretium ut tempor urna molestie. Maecenas metus enim, venenatis vel volutpat non, iaculis ut justo. Nulla venenatis malesuada quam at tincidunt. Nunc at sem eros, convallis eleifend arcu. Curabitur gravida velit nec nunc condimentum feugiat. In ultrices orci sit amet purus fermentum placerat in et lacus. Praesent sit amet sodales lectus. Morbi vehicula condimentum purus eu vulputate. Morbi risus enim, rhoncus a iaculis et, porta vitae justo." 
    />
<ListView android:id="@+id/lv" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"></ListView>
 </demo.fling8.HorizontalPager>

在我MainActivity.java类,这是我的code来填充的ListView。

in my MainActivity.java class, this is my code to populate the ListView.

 List<MyObject> dataList = DataAccessService.getDummyData();
 ListView listView = (ListView)findViewById(R.id.lv);
 listView.setAdapter(new MyAdapter(this, R.id.textViewTitle, dataList));

如果你抛球或刷卡,你会发现,TextView的不从有透明背景的这种效果受苦(整个屏幕为黑色)。当甩到ListView,如果只有几排,然后从那里在ListView结束到屏幕的底部,有一个透明的背景

if you "fling" or "swipe", you will notice that the TextView does not suffer from this effect of having a transparent background (the whole screen is black). when you fling to the ListView, if there are only a few rows, then from where the ListView ends to the bottom of the screen, there is a transparent background.

下面是对项目文件的链接: http://www.box.net/shared/5pybcpj8mkbfhv3j3ach 。请让我知道,如果你不能访问它。如果部署到您的设备,你应该看到(透明背景)的效果。

here is a link to the project file: http://www.box.net/shared/5pybcpj8mkbfhv3j3ach. please let me know if you cannot access it. if you deploy to your device you should see the effect (of a transparent background).

下面是另一个项目文件的链接: http://www.box.net/shared/i9vs6yq9j2s4ysp994et 。该项目文件只使用一个Horizo​​ntalScrollView(未上面引用的组件)。因为你可能会看到,有透明的背景。

here is a link to another project file: http://www.box.net/shared/i9vs6yq9j2s4ysp994et. this project file uses only a HorizontalScrollView (not the component referenced above). as you will probably observe, there is the transparent background.

推荐答案

如果您正在寻找实现横向分页看到在兼容性库中的 ViewPager 部件:的 http://developer.android.com/sdk/compatibility-library.html 它的工作原理所有回到运行Android 1.6设备的方式。它也可以让你只保留了几页活在任何特定时间,让您的视图层次更简单,让您在大型数据集。

If you are looking to implement horizontal paging see the ViewPager widget in the compatibility library: http://developer.android.com/sdk/compatibility-library.html It works all the way back to devices running Android 1.6. It also allows you to only keep a few pages "live" at any given time, keeping your view hierarchy much simpler and allowing you to work with large data sets.

这篇关于添加ListView的孩子去Horizo​​ntalScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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