This is may layout xml:
<RelativeLayout
android:id="@+id/seek_bar_wrapper"
android:layout_width="match_parent"
android:layout_height="200dip">
<SeekBar
android:id="@+id/seek_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="20dip"
android:maxHeight="2dip"
android:minHeight="2dip"
android:progressDrawable="@drawable/drawable_seekbar_progress"
android:thumb="@drawable/drawable_seekbar_thumb" />
</RelativeLayout>
I set an OnClickListener
to the RelativeLayout
. The strange thing is that when I touch the RelativeLayout
, the SeekBar
performs like I press it, it's thumb become the drawable when it's state is pressed. I think it's state become pressed.
Is this a bug and how to deal with it?
Just set
android:clickable="true"
android:focusable="true"
To your seekbar
ViewGroups
seem to pass their state down to their children when they are clickable as seen in this question: View gets its drawable state (pressed, etc...) from its parent
This may be happening because you set the OnClickListener
to the RelativeLayout
.
My first inclination would be to put a Button
behind the SeekBar
as a sibling to the SeekBar
, and using that for your OnClick action.
You could also override your RelativeLayout
, and do nothing on setPressed
Android: Child elements sharing pressed state with their parent even when duplicateParentState specified
According to the docs: http://developer.android.com/training/gestures/viewgroup.html
Handling touch events in a ViewGroup takes special care, because it's common for a ViewGroup to have children that are targets for different touch events than the ViewGroup itself. To make sure that each view correctly receives the touch events intended for it, override the onInterceptTouchEvent() method.
So it seems this is intended behavior. If you want to avoid this behavior it looks like you will need to override the ViewGroup
(RelativeLayout
) or use a View
that is not a parent to the SeekBar
for this event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With