如果布局上有ScrollView,则OnItemClick不起作用

时间:2014-02-14 15:42:56

标签: android android-listview onitemclicklistener

我有一个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工作。

有什么想法吗? 感谢。

2 个答案:

答案 0 :(得分:0)

问题是:你的ScrollView。

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

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

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

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

答案 1 :(得分:0)

好吧,我已经研究了评论和aswers,并尝试实施其他解决方案。在这里我找到了。

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

因为ScrollView会破坏焦点和侦听器,无法实现。

在大图片的情况下,以图形方式裁剪图像需要花费大量时间。它也无法实施。

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

我希望它对任何人都有帮助。

相关问题