GridView 中的 ListView 不滚动? [英] ListView inside GridView not Scrolling?

查看:24
本文介绍了GridView 中的 ListView 不滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示项目的 GridView,每个项目都是一个 ListView.

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

问题是我无法滚动 ListView 项目,似乎 GridView 正在从 ListViews 获取焦点或阻止它

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

是否有解决方法?

谢谢

**

**这是我的活动布局

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

每个 gridview 项具有以下布局:

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>

推荐答案

在可滚动的父视图中不能有可滚动的子视图.谷歌不推荐它......它真的很乱.阅读本文

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.

它不起作用的主要原因之一是可滚动视图处理触摸的方式.有一个名为 dispatchTouchEvent()onInterceptTouchEvent() 的方法决定是拦截触摸事件还是将其传递给它的子级.对于可滚动视图,它们将始终拦截滑动"动作.所以它永远不会给你的孩子.

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.

这篇关于GridView 中的 ListView 不滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆