【问题标题】:OnItemClick doesnt work if there is ScrollView on layout如果布局上有 ScrollView,则 OnItemClick 不起作用
【发布时间】:2014-02-14 15:42:56
【问题描述】:

我有一个 ListView,这是它的行布局

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="280dp">
<ScrollView
    android:scrollbars="none"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/exploreImage"
        android:src="@drawable/beard1"
        android:adjustViewBounds="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</ScrollView>
<TextView
    android:id="@+id/exploreText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</RelativeLayout>

我必须在我的布局中实现 ScrollView,描述是 here

所以,我的问题是我设置为 listView 的 OnItemClickListener 不起作用。我可以实现 OnTouchListener,但在这种情况下,我需要知道被点击项目的位置和 id。

UPD1:我的 listView 的代码。 这里是

 <ListView 
    android:id="@+id/exploreList"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

UPD2:我不需要滚动这个 ScrollView,只需要滚动 ListView。我也想要 OnItemClickListener 工作。

有什么想法吗? 谢谢。

【问题讨论】:

  • 您的列表视图在哪里?我没有看到列表视图!
  • @WarrenFaith 我展示了我的行布局代码,我的 ListView 代码会有帮助吗?哦
  • 假设你想检测列表中被点击的项目为什么不使用 onListItemClick ?如果您不想检测被点击的列表项,那么我不明白您的问题。
  • 好的,您希望滚动容器(您所在行中的 ListView 和 ScrollView)如何确定您想要滚动的内容?恕我直言,您的设计有缺陷!
  • @pedromss 确切地说,我想检测点击了哪个项目。我写道,OnItemClickListener 在我的行布局中不起作用,原因是 ScrollView。

标签: android android-listview onitemclicklistener


【解决方案1】:

问题是:你的 ScrollView。

我们可以给出的基本答案是:找到另一种方式,以您想要的方式在行内显示图像。基本上只是搜索如何裁剪图像并裁剪它以使其适合。

用于裁剪图像的未经测试的代码:

Bitmap croppedBitmap = Bitmap.createBitmap(bitmapOriginal, destWidth, destHeight, bitmapOptions);

可以在Bitmap 文档中找到一些替代方法。

【讨论】:

    【解决方案2】:

    好吧,我研究了 cmets 和 aswers 并尝试实施其他解决方案。这是我发现的。

    要求是 - 将图像绑定到 View 的顶部和侧面,并在底部进行裁剪。但是这个 View 是像 ListView 中的 item 一样实现的,所以我必须将所有的 focus 和 listeners 保存在 ListView 中。

    因为ScrollView破坏了focuss和listeners,所以无法实现。

    在大图片的情况下,以编程方式裁剪图像需要大量时间。也无法实现。

    我决定这样做的方式是覆盖 ImageView 中的 onMeasure 方法,就像在 topic 中描述的那样。

    希望对大家有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-24
      • 2020-12-22
      • 1970-01-01
      相关资源
      最近更新 更多