Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollView with Buttons inside, no response until second click on any button inside

I've been a couple of days trying to solve this thing but I can't figure it out. The problem is, simple activity, with simple layout, ScrollView -> LinearLayout -> and a lot of buttons inside the layout (within the scroll content). Everything works just fine, but one tricky thing. When I click a button, let's say at the top of the scroll content and immediately scroll down to the bottom of the content and click another button there, nothing happens until I click a second time and all comes to normal again. This can be reproduced anytime and it's code independent (I've tried more than 20 scenarios). I don't have much experience in Android yet, but looks like the scroll listener stops the onClick listener or something like that. Any help with this would be much appreciated. Thank you in advance.

PD. If I programmatically do a scrollTo(), instead of manual scroll with my fingers, everything works just fine and the click responds at first touch. It's simply overwhelming me.

like image 951
esenian Avatar asked Oct 30 '10 23:10

esenian


3 Answers

Everything is behaving normally.

When you start scrolling, the ScrollView will claim touch events until you stop touching the screen for a bit. In Android 2.2, you will know when scrolling is deemed complete, because the scrollbar on the right will fade away.

like image 28
CommonsWare Avatar answered Nov 19 '22 17:11

CommonsWare


I got a situation like this. I have a ExpandableListView, it just behaves normally. When I rotate the cellphone to horizontal, and rotate back, then some items in one group of the ExpandableListView will not responding for click event. Unless I scroll the list view, or click the group item of these items, the event will dispatch to the items I clicked previously, and perform the click listener codes correctly.

This happened both in android 2.3 and 4.0...

like image 44
bbsimon Avatar answered Nov 19 '22 16:11

bbsimon


I have the same problem. I disagree that it's a fading scrollbar issue. If you disable the fading, the same thing happens.

Tried several approaches in themes.xml:

<item name="android:scrollbarDefaultDelayBeforeFade">100</item>
<item name="android:scrollbarFadeDuration">100</item>
<item name="android:fadeScrollbars">true</item>

But nothing helped. It seems that it's a system thing with scrollViews. This might help to see what's going on:

setOnScrollListener(new OnScrollListener(){
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
      // TODO Auto-generated method stub
    }
    public void onScrollStateChanged(AbsListView view, int scrollState) {
      // TODO Auto-generated method stub
      if(scrollState == 0) Log.i("a", "scrolling stopped...");
    }
  });
}

But that (unfortunately) doesn't help in overcoming the problem - but rather explaining it.

NOTE: this only happens if you use ScrollView. ListView doesn't have this problem.

Anyone has another idea ?

like image 147
humbleSapiens Avatar answered Nov 19 '22 18:11

humbleSapiens