Reputation: 71
When I put my Buttons in a GridLayout
the touch response is visually different than normally. On quick touch the change from default state to pressed state looks like normal, but when I touch and hold there is a very noticeable delay before the pressed button drawable is shown. Any idea of why?
I have tried to move the Button outside of the GridLayout
and then it behaves like normal again - it changes to pressed state immediately. I have also tried android:longClickable="false"
but that didn't solve the problem.
Here is my simple test:
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="80dp"
android:layout_height="80dp"
android:text="1"
android:textStyle="bold"
android:textSize="40dp"
android:background="@drawable/num_button"/> <!-- Same result without this drawable-->
</GridLayout>
My test device is a Google Nexus 10 running KitKat.
Upvotes: 0
Views: 677
Reputation: 522
I had the same problem, but I found a fix in a similar post here on SO.
You need to override a button and add the following code:
public boolean onTouchEvent (MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_DOWN) setPressed(true);
return super.onTouchEvent(event);
}
Upvotes: 1