简体   繁体   English

将ListView放入Horizo​​ntalScrollView的最佳方法是什么?

[英]What is the best way to put a ListView inside HorizontalScrollView?

I'm trying to make a calendar app and will like to list all the events of a day on a ListView and scroll horizontally the days. 我正在尝试制作日历应用程序,并希望在ListView上列出一天中的所有事件并水平滚动这些天。 When I scroll to the right, ListView should redraw the events for tomorrow. 当我向右滚动时,ListView应该为明天重新绘制事件。 I have all my events in a sqllite database. 我将所有事件都存储在sqllite数据库中。

This is how my XML looks like: 这是我的XML的样子:

<?xml version="1.0" encoding="UTF-8"?>       

<HorizontalScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" 
    android:scrollbars="none">

    <LinearLayout
        android:id="@+id/layout"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:gravity="center"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <ListView android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

    </LinearLayout>

</HorizontalScrollView>

How can I populate the ListView and make it get the new data every time I scroll? 如何在每次滚动时填充ListView并使其获取新数据?

Wrong approach, a ListView can't be nested inside a ScrollView. 错误的方法是,ListView不能嵌套在ScrollView中。 Use a ViewPager to page the days. 使用ViewPager页面。

I have used a ListView inside a HorizontalScrollView in API 15 and 18. Both views seem to recognize their required gesture, so it works. 我在API 15和18中的Horizo​​ntalScrollView中使用了ListView。这两个视图似乎都可以识别其所需的手势,因此可以正常工作。 One thing I noticed however is that the width of the ListView is only as wide as the first row in the list. 但是,我注意到的一件事是ListView的宽度仅与列表中的第一行一样宽。 If subsequent rows are wider the "extra" (length in excess of row 1) won't be visible, but then you can scroll over to see the remaining text, etc... I haven't noticed any other ill effects. 如果随后的行更宽,则“额外”(超出行1的长度)将不可见,但是您可以滚动查看其余文本,等等。。。我还没有发现其他不良影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM