【问题标题】:Can not scroll and click item on gridview inside scrollview无法滚动并单击滚动视图内的网格视图上的项目
【发布时间】:2013-08-14 12:53:15
【问题描述】:

好的,伙计们,我有这样的布局

<ScrollView
android:id="@+id/scrollViewTree"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<include
android:id="@+id/layoutGallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/layout_gallery_obstruction" >
</include>

</ScrollView>

这是*layout_gallery_obstruction*

?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/textViewGalleryObs"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/buttonGalleryObs"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="@string/obstruction_title_gallery" />

    <Button
        android:id="@+id/buttonGalleryObs"
        android:layout_width="100dp"
        android:layout_height="35dp"
        android:layout_marginLeft="30dp"
        android:layout_toRightOf="@+id/textViewGalleryObs"
        android:text="@string/obstruction_gallery_add"
        android:textSize="12sp" />

    <GridView
        android:id="@+id/gridViewGalleryObs"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignLeft="@+id/textViewGalleryObs"
        android:layout_below="@+id/buttonGalleryObs"
        android:columnWidth="90dp"
        android:gravity="center"
        android:horizontalSpacing="5dp"
        android:numColumns="4"
        android:stretchMode="columnWidth"
        android:verticalSpacing="5dp" >
    </GridView>

</RelativeLayout>

我为我的 gridview 使用自定义适配器,这是单元格的布局

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

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@android:color/transparent"
        android:contentDescription="@string/app_name" />

</RelativeLayout>

好的,我的问题是,我无法滚动 gridview ,也无法单击 gridview 上的项目。有人知道如何解决这个问题吗?谢谢你。 :)

【问题讨论】:

  • 正如 kettu 所说,我也会将 GridView 放入 ScroolView。目前,您在 Gridview 上方只有一个 TextView 和 Button -> 我会将它们设置在 GridView 上方。但是您可以在这篇帖子stackoverflow.com/questions/6210895/… 中尝试@Moisés Olmedo 的解决方案。那真的很简单也很好。希望这会对你有所帮助:)
  • 哇太好了,我在这条评论中找到了解决方案> stackoverflow.com/questions/6210895/… 是的,我必须制作一个自定义滚动视图(从滚动视图类扩展).. :) 谢谢你给我那个链接.. : )

标签: android gridview scrollview


【解决方案1】:

启用您的 GridView 属性为

android:nestedScrollingEnabled="true"。

【讨论】:

  • RecyclerView 中需要 API 21,但对我没有帮助。
【解决方案2】:

无需将 gridview 放入 scrollview 并点击项目我希望 this 对您有所帮助

【讨论】:

  • 在我的情况下,我认为我必须把它放在滚动视图上,因为这个布局中有很多组件(不仅仅是网格视图)。有edittexts、spinner、textview等,所以我想在这种情况下我必须使用scrollview。
  • 项目点击怎么样?它起作用了吗? stackoverflow.com/questions/18142646/…
  • 是的,我已经完成了项目的点击,我只是发现在 gridview 中我们不应该放置一个可点击的对象。所以我只是用图像视图更改图像按钮。
【解决方案3】:

好的,我的问题已经解决了。 :) 感谢所有向我展示线索的人。 :D

首先在滚动视图中滚动gridview,基本上我们不应该在滚动视图中放置gridview,但这并不意味着我们不能这样做。我们只需要使用自定义滚动视图,我从这条评论中找到它 > https://stackoverflow.com/a/11554684/2496348

关于gridview onItemClickListener,我们不能在gridview里面放一个可点击的对象,所以我只是把imagebutton改成imageview。

就是这样!谢谢:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多