【问题标题】:Scrollview inside ListviewListview 内的滚动视图
【发布时间】:2013-02-20 15:52:34
【问题描述】:

我有一个包含多行的列表视图,其中一行必须是包含多行的列表视图,但只需要显示其中的 2 个,其余的仅在滚动时显示。我在布局文件的列表视图中添加了一个带有 LinearLayout 的 ScrollView,并且我在 java 文件中添加了行的内容。 ScrollView 似乎不能很好地滚动。有没有更好的方法来实现这一目标? 这是我的布局文件。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ListView
    android:id="@android:id/list"
    android:layout_width="1px"
    android:layout_height="1px"
    android:layout_weight="1"
    android:cacheColorHint="#00000000"
    android:scrollbars="vertical" >
</ListView>

<RelativeLayout
    android:id="@+id/listItem"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/formImage"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY" />

    <include layout="@layout/vertical_list_item_title_area" />
</RelativeLayout>


    <ScrollView
    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:fillViewport="true"
    android:layout_weight="1">

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

    </LinearLayout>
</ScrollView>

<com.illumemobile.testapp.Classes.SCClasses.SCActivities.SCCustomActivities.SCCustomGallery
    android:id="@+id/horizontallistview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    android:spacing="33dip" />

【问题讨论】:

    标签: android


    【解决方案1】:

    ListViews 内部的 ScrollViews 是一个非常非常糟糕的主意。这不仅让用户感到困惑,而且系统在确定哪个 View 应该获取触摸事件方面存在问题。

    我建议重新考虑您的布局。

    【讨论】:

    • 但这在某些情况下是必需的
    • 如果问题正文中的代码块是可滚动的,而整个页面也可滚动,这是一个非常非常糟糕的主意吗? StackOverflow 是否也应该重新考虑其 UI 布局?
    • 你可以为所欲为,我只知道这不是一个好主意。首先,滚动视图拦截滚动事件。你有没有尝试过使用鼠标滚轮滚动到堆栈溢出帖子的底部,该帖子有一堆长代码 sn-ps?这不是最好的体验。事实上,stack 会在他们的移动应用程序中自动扩展这些块的高度来避免这个问题。其次,你有没有试过在 Stack 上使用 narrator?这是不存在的。事实上,Windows 应用商店在整个页面垂直滚动中使用水平列表启动,并迅速改变了设计。
    • 我知道它可能不是“最好的” UI 体验,但在某些情况下需要它,尽管这是一个坏主意,但这个用户(和我自己)发现了一个案例,它是要求。用“重新考虑你的布局”来回答是不可接受的,尤其是当我们是程序员并且我们应该找到解决问题的方法时。
    【解决方案2】:

    我建议制作一个 ScrollView,然后在滚动视图中制作一个 LinearLayout。在该 LinearLayout 中,您可以将更多 LinearLayouts 一个或多个项目作为子项。我认为这将接近你想要做的事情......我更喜欢使用 ScrollViews 和 LinearLayouts 而不是尝试处理 ListViews。根据我的经验,LinearLayouts 比 ListViews 动态得多。 -希望这会有所帮助

    【讨论】:

      猜你喜欢
      • 2018-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      相关资源
      最近更新 更多