我有一个使用 RadioButtons 作为其句柄的自定义可拖动 SlidingDrawer。为了在 RadioButtons 上启用触摸事件,我调用return super.onInterceptTouchEvent(event);
而不是return true
在onInterceptTouchEvent
方法上。但不知何故,每次我想拖动我的 SlidingDrawer 时,我都无法通过准确地触摸 RadioButtons 来拖动它,我必须向上移动一点手指才能将 SlidingDrawer 向上拖动。
有什么方法可以通过触摸其 RadioButtons 来使 SlidingDrawer 完全可拖动,而不会丢失 RadioButtons 本身上的 TouchEvent?
这是我的触摸方法:
public boolean onInterceptTouchEvent(MotionEvent event) {
if (mLocked) {
//return false;
}
final int action = event.getAction();
float x = event.getX();
float y = event.getY();
final Rect frame = mFrame;
final View handle = mHandle;
handle.getHitRect(frame);
if (!mTracking && !frame.contains((int) x, (int) y)) {
return false;
}
if (action == MotionEvent.ACTION_DOWN) {
mTracking = true;
WWHApplication.getListActivityIntance().resizeListView(1800);
handle.setPressed(true);
// Must be called before prepareTracking()
prepareContent();
// Must be called after prepareContent()
if (mOnDrawerScrollListener != null) {
mOnDrawerScrollListener.onScrollStarted();
}
if (mVertical) {
final int top = mHandle.getTop();
mTouchDelta = (int) y - top;
prepareTracking(top);
} else {
final int left = mHandle.getLeft();
mTouchDelta = (int) x - left;
prepareTracking(left);
}
mVelocityTracker.addMovement(event);
}
//return true;
return super.onInterceptTouchEvent(event);
}
这是我的手柄的样子
<LinearLayout
android:id="@+id/handle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tab_content_bg_top" />
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tab_content_bg"
android:fillViewport="true"
android:scrollbars="none" >
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/cb_tab_all"
android:layout_width="46dp"
android:layout_height="45dp"
android:background="@drawable/checkbox_background"
android:button="@drawable/tab_all_selector"
android:onClick="true" />
<RadioButton
android:id="@+id/cb_tab_favorites"
android:layout_width="84dp"
android:layout_height="45dp"
android:background="@drawable/checkbox_background"
android:button="@drawable/tab_favorites_selector"
android:onClick="true" />
<RadioButton
android:id="@+id/cb_tab_historical"
android:layout_width="134dp"
android:layout_height="45dp"
android:background="@drawable/checkbox_background"
android:button="@drawable/tab_historical_selector"
android:onClick="true" />
<RadioButton
android:id="@+id/cb_tab_food"
android:layout_width="116dp"
android:layout_height="45dp"
android:background="@drawable/checkbox_background"
android:button="@drawable/tab_food_selector"
android:onClick="true" />
</RadioGroup>
</HorizontalScrollView>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tab_content_bg_bottom" />
</LinearLayout>