将 ListView 子级添加到 Horizo​​ntalScrollView

发布于 2024-11-29 23:28:57 字数 2504 浏览 2 评论 0原文

我有一个 Horizo​​ntalScrollView,并且我添加了一堆 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.Horizo​​ntalPager 复制/粘贴到我的包中。

 <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。该项目文件仅使用 Horizo​​ntalScrollView(不是上面引用的组件)。正如您可能会观察到的那样,有透明的背景。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夕嗳→ 2024-12-06 23:28:57

如果您想实现水平分页,请参阅兼容性库中的 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.

小ぇ时光︴ 2024-12-06 23:28:57

您可以省略 Horizo​​ntalScrollView,因为 ListView 会自动展开,如果没有空间,它会自动滚动。只需使用

    <LinearLayout>
    <ListView android:id="@+id/listView1"/>
    </LinearLayout>

You may omit HorizontalScrollView as ListView automatically expand and if there is no room it Scroll automatically. Simply use

    <LinearLayout>
    <ListView android:id="@+id/listView1"/>
    </LinearLayout>
行至春深 2024-12-06 23:28:57

我不确定这是否有帮助,但可能会

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

I'm not sure if this will help, but it might

<HorizontalScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
 <LinearLayout>
  <ListView android:id="@+id/listView1" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
 </LinearLayout>
</HorizontalScrollView>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文