OnItemClick doesnt work if there is ScrollView on layout

拜拜、爱过 提交于 2019-12-25 02:29:13

问题


I have a ListView and here is its row layout

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

I had to implement ScrollView in my layout, description is here.

So, my trouble is OnItemClickListener that I set to listView doesnt work. I could implement OnTouchListener, but in the case I need to know position and id of the clicked item.

UPD1: code of my listView. Here it is

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

UPD2: I dont need to scroll this ScrollView, only ListView. Also I want OnItemClickListener work.

Any ideas? Thanks.


回答1:


The problem is: Your ScrollView.

The basic answer we can give: Find another way to display the image inside the row in the way you want it. Basically just search on how to crop an image and crop it so that it fits.

Untested code to crop your image:

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

Some alternative methods can be found in the Bitmap documentation.




回答2:


Well, I have researched comments and aswers and tried to implement other solution. And here what I found.

The requirement was - to bind the image to the top and sides of View with cropping it in the bottom. But this View is implemented like item in the ListView, so I have to save all the focuses and listeners in the ListView.

Cause the ScrollView destroys the focuses and listeners, it cant be implemented.

Cropping the image programmaticaly takes a lot of time in the case of big pictures. It also cant be implemented.

The way I decided to do it is overriding the onMeasure method in the ImageView, like it's described in the topic.

I hope it will help to anyone.



来源:https://stackoverflow.com/questions/21783536/onitemclick-doesnt-work-if-there-is-scrollview-on-layout

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