将 ListView 子级添加到 HorizontalScrollView
我有一个 HorizontalScrollView,并且我添加了一堆 ListView 作为其子项。我的 XML 文件如下所示。为了简洁起见,我将省略一些属性。
<HorizontalScrollView>
<LinearLayout>
<ListView android:id="@+id/listView1" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
</LinearLayout>
</HorizontalScrollView>
在我的java代码中,我用数据填充ListView。如果只有 1 或 2 条记录,ListView 不会一直延伸到屏幕底部。我看到似乎是透明背景。我该如何摆脱这种行为。
我还尝试使用 http://www.matt-reid 中的此组件。 co.uk/blog_post.php?id=62。我又遇到了同样的问题。
任何帮助表示赞赏。
下面是 XML 文件。我只是将控制代码作为 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 类中,这是我填充 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结束的地方到屏幕底部,有一个透明的背景。
这是项目文件的链接:http://www.box.net/shared/5pybcpj8mkbfhv3j3ach。如果您无法访问,请告诉我。如果您部署到您的设备,您应该会看到效果(透明背景)。
这是另一个项目文件的链接: http://www.box.net/shared/i9vs6yq9j2s4ysp994et。该项目文件仅使用 HorizontalScrollView(不是上面引用的组件)。正如您可能会观察到的那样,有透明的背景。
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>
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.
i also tried using this component from http://www.matt-reid.co.uk/blog_post.php?id=62. again, i have the same problem.
any help is appreciated.
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>
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));
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.
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).
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想实现水平分页,请参阅兼容性库中的
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.您可以省略 HorizontalScrollView,因为 ListView 会自动展开,如果没有空间,它会自动滚动。只需使用
You may omit HorizontalScrollView as ListView automatically expand and if there is no room it Scroll automatically. Simply use
我不确定这是否有帮助,但可能会
I'm not sure if this will help, but it might