我有一个自定义可拖动的SlidingDrawer,使用RadioButtons作为其句柄。为了在RadioButtons上启用触摸事件,我在return super.onInterceptTouchEvent(event);
方法上调用return true
而不是onInterceptTouchEvent
。但不知怎的,每当我想拖动我的SlidingDrawer时,我无法通过触摸RadioButtons完全拖动它,我必须向上移动一点手指向上拖动SlidingDrawer。
有没有什么方法可以通过触摸RadioButtons而不丢失RadioButtons本身的TouchEvent来使SlidingDrawer完全可拖动?
谢谢。
这是我的触控方式:
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>