ListView inside GridView not Scrolling?

给你一囗甜甜゛ 提交于 2019-12-19 09:47:18

问题


I have a GridView that displays items, each item is a ListView.

the problem is that I can't scroll the ListView items, seems like the GridView is obtaining the focus or preventing it from the ListViews

is there a workaround for this ?

thanks

**

EDIT:

** here's my activity layout

<GridView
        android:id="@+id/grid"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:verticalSpacing="35dp"
        android:horizontalSpacing="10dp"
        android:numColumns="auto_fit"
        android:columnWidth="300dp"
        android:stretchMode="columnWidth"

        />
</LinearLayout>

each gridview item has the following layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
     >

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

</LinearLayout>

回答1:


You cannot have a scrollable child view within a parent view that is scrollable. Google does not recommend it... and it's really messy. Read this

There have been people who've been trying to do a workaround (which doesn't look pretty), but I doubt it will work for you. But you can read it anyways and see if you can make it work for you. Enjoy.

One of the main reasons why it wont work is because of the way scrollable views handle touch. There's a method called dispatchTouchEvent() and onInterceptTouchEvent() that decides whether to intercept the touch event or pass it to it's children. For scrollable views, they will always intercept "swipe" movements. So it will never go to your children.

You can try to modify it, but if you think about it, how will you know if you're trying to scroll the parent or if you're trying to scroll the child? Imagine if the one of your scrollable children ends up taking the width of your screen, but then you want to scroll your parent, how will you manage that?

Summary: it's not recommended .... if you really insist... then go ahead and write your own custom view to handle the logic. But i guarantee you it wont be pretty and will almost never work for all use cases.




回答2:


set attribute android:scrollingCache="true" in your ListView

<ListView android:id="@+id/android:list" 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:scrollingCache="true"
   android:layout_weight="1" />


来源:https://stackoverflow.com/questions/9295794/listview-inside-gridview-not-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!