Android 滚动视图中的ListView和GridView。ScrollView赢得';滚动

Android 滚动视图中的ListView和GridView。ScrollView赢得';滚动,android,listview,gridview,scrollview,Android,Listview,Gridview,Scrollview,首先,我想为我的英语阿波罗吉兹,我来自俄罗斯,我希望谷歌翻译帮助我描述我的问题=)。 所以问题是-我在ScrollView中有一个gridView和ExpandableListView,我知道我不应该在ScrollView中放一个可滚动的视图,但对于我的目标,我找不到替代方案。在我的项目中,我有一个包含类别(如“电子产品”、“家庭与花园”、“汽车”等)的商业目录,我所要做的就是将最受欢迎的类别放入gridView(并向其中添加图标),并使scrollview像单个布局一样滚动。但是我的scrol

首先,我想为我的英语阿波罗吉兹,我来自俄罗斯,我希望谷歌翻译帮助我描述我的问题=)。 所以问题是-我在ScrollView中有一个gridView和ExpandableListView,我知道我不应该在ScrollView中放一个可滚动的视图,但对于我的目标,我找不到替代方案。在我的项目中,我有一个包含类别(如“电子产品”、“家庭与花园”、“汽车”等)的商业目录,我所要做的就是将最受欢迎的类别放入gridView(并向其中添加图标),并使scrollview像单个布局一样滚动。但是我的scrollView不会滚动它,我怎么能做到呢

我的生活:

我的目录布局:

<?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>   


使用GridView而不是GridView。

使用GridView而不是GridView。

根据Android指南,您不能将一个可滚动布局使用到另一个。如果您使用的是ScrollView,则不能在其中使用ListView。因为这两种布局都是可滚动的。因此,请使用任何一个来滚动您的页面。

根据Android的指导原则,您不能使用一个可滚动的布局来滚动另一个。如果您使用的是ScrollView,则不能在其中使用ListView。因为这两种布局都是可滚动的。因此,请使用任意一个滚动视图。

您可以通过覆盖滚动视图的
dispatchTouchEvent(MotionEvent事件)
功能来实现上述功能。在此函数中,将事件发送到子listview。然后还需要像这样覆盖listview的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);
int[]位置=新的int[2];
listView.getLocationOnScreen(位置);
如果(e.getRawX()>location[0]&&e.getRawX()位置[1]&e.getRawY()
您可以通过覆盖滚动视图的
dispatchTouchEvent(MotionEvent事件)
功能来实现上述功能。在此函数中,将事件发送到子listview。然后还需要像这样覆盖listview的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);
int[]位置=新的int[2];
listView.getLocationOnScreen(位置);
如果(e.getRawX()>location[0]&&e.getRawX()位置[1]&e.getRawY()
首先删除滚动视图。使用listview并将gridview添加为listview的footerview。这将非常有效。绝对可以解决您的问题。

首先删除滚动视图。使用listview并将gridview添加为listview的footerview。这将非常有效。绝对可以解决您的问题。

如果您希望在滚动视图中显示适配器视图,那么您必须解决这个问题。我认为您没有任何其他选择如果您想要在滚动视图中显示适配器视图,您必须处理地狱。我以为您没有其他选择Ok,我会试试(我知道我可以将gridview添加到listview标题中)好的,我会试试(我知道我可以将gridview添加到listview标题中)