【问题标题】:ListView and GridView inside ScrollView. ScrollView won't scrollingScrollView 中的 ListView 和 GridView。 ScrollView 不会滚动
【发布时间】:2013-10-01 21:33:51
【问题描述】:

首先我想为我的英语道歉,我来自俄罗斯,我希望谷歌翻译器能帮助我描述我的问题=)。 所以问题是 - 我在 ScrollView 中有一个 gridView 和 ExpandableListView,我知道我不应该在 ScrollView 中放置一个可滚动的视图,但为了我的目标,我找不到替代方案。在我的项目中,我有一个包含类别的业务目录(如“电子”、“家庭和花园”、“汽车”等),我要做的就是将最流行的类别放入 gridView(并向它们添加图标)并制作滚动视图像单一布局一样滚动它。但是我的scrollView不会滚动它,我该怎么做?

我的 bizCatalog 活动:

我的 bizCatalog 布局:

<?xml version="1.0" encoding="utf-8"?>
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bizSwitcher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Загрузка списка..." />
</LinearLayout>

<ScrollView
    android:id="@+id/bizScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <GridView
            android:id="@+id/bizFavoritesGrid"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:columnWidth="90dp"
            android:gravity="center"
            android:horizontalSpacing="10dp"
            android:numColumns="auto_fit"
            android:paddingTop="10dp"
            android:stretchMode="columnWidth"
            android:verticalSpacing="10dp" >
        </GridView>

        <ExpandableListView
            android:id="@+id/bizList"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:cacheColorHint="#00000000" >
        </ExpandableListView>
    </LinearLayout>
</ScrollView>

</ViewSwitcher>   

【问题讨论】:

    标签: android listview gridview scrollview


    【解决方案1】:

    使用GridLayout代替GridView。

    【讨论】:

      【解决方案2】:

      根据 Android 指南,您不能将一种可滚动布局用于另一种。如果您使用的是 ScrollView,那么您不能在其中使用 ListView。因为这两种布局都是可滚动的。所以请使用任何一个来滚动你的。

      【讨论】:

        【解决方案3】:

        您可以通过覆盖滚动视图的dispatchTouchEvent(MotionEvent event) 函数来实现上述目的。在这个函数内将事件发送到您的子列表视图。那么你还需要像这样为你的列表视图覆盖 dispatchTouchEvent

          int[] location = new int[2];
          listView.getLocationOnScreen(location);
        
          if (e.getRawX() > location[0] && e.getRawX()< location[0] + listView.getWidth() &&
           e.getRawY() > location[1] && e.getRawY() < location[1] + listView.getHeight())
          {
            int[] checkListLoc = new int[2];
        
            listView.getLocationOnScreen(checkListLoc);
            var offset = checkListLoc[1] - (e.getRawY() - e.GetY());
            e.OffsetLocation(0, 0 - offset);
        
            listView.dispatchTouchEvent(e);
            return true;
         }
         return base.dispatchTouchEvent(e);
        

        【讨论】:

        • 如果你想在滚动视图中使用适配器视图,你必须处理地狱。我以为你别无选择
        【解决方案4】:

        首先删除滚动视图。使用 listview 并将 gridview 添加为 listview 的页脚视图。它会很好用。绝对解决你的问题。

        【讨论】:

        • 好的,我试试看(我知道我可以将gridview添加到listview header中)
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-09-03
        • 2013-09-19
        • 2015-07-29
        • 2016-06-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多