您可以使用LinearLayout作为 SlidingDrawer 容器的句柄或内容元素的容器。如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<SlidingDrawer android:id="@+id/drawer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="showPopUp"
android:handle="@+id/handle"
android:content="@+id/content">
<LinearLayout android:id="@id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- here goes your content -->
</LinearLayout>
<LinearLayout android:id="@id/handle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffff5600"
android:orientation="horizontal">
<TextView android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:layout_gravity="left"
android:text="musicas" />
<Button android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="showPopUp"
android:text="+" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
它允许您像上面的屏幕截图一样进行布局,但它不允许捕获按钮按下事件。为此,我进行了一些研究,并建议覆盖 MultiDirectionSlidingDrawer(来源http://blog.sephiroth.it/2011/03/29/widget-slidingdrawer-top-to-bottom/)。我这样做如下:在onInterceptTouchEvent()方法中,我添加了以下代码final View handle = mHandle;
boolean handleTouch = false;
if (mHandle instanceof ViewGroup) {
ViewGroup group = (ViewGroup) mHandle;
int count = group.getChildCount();
for (int i = 0; i < count; i++) {
View v = group.getChildAt(i);
v.getHitRect(frame);
if (frame.contains((int) x, (int) y)) {
handleTouch = v.onTouchEvent(event);
if (handleTouch) {
return false;
}
}
}
}
现在它分别处理来自按钮和抽屉本身的事件。