我正在使用滑动抽屉小部件在我的 Android 应用程序中构建视图。我已经实现了我自己的自定义句柄(只是一排菜单按钮,然后更改抽屉的内容,然后激活 openAmination)。我已经设法禁用了滑动抽屉提供的标准手柄,但我想完全移除它。
xml 或 java 中的标准可见性内容都不能用于隐藏/删除句柄:
<SlidingDrawer android:layout_width="fill_parent"
android:id="@+id/slidingDrawer1"
android:layout_height="fill_parent"
android:handle="@+id/handle"
android:content="@+id/content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:allowSingleTap="false"
>
<Button android:layout_width="wrap_content"
android:text="Close"
android:layout_height="wrap_content"
android:id="@+id/handle"
android:visibility="gone" //DOES NOT WORK
</Button>
<LinearLayout android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
</LinearLayout>
</SlidingDrawer>
我也尝试在 java 中导入视图并做同样的事情,但也不起作用。
View h = findViewById(R.id.handle);
h.setVisibility(View.GONE);
然后我尝试扩展slidingDrawer类并制作我自己的,但它仍然需要一个句柄!。反正我有一个没有默认把手的滑动抽屉吗?
- - -解决方案 - -
draw = (SlidingDrawer)findViewById(R.id.slidingDrawer1);
//Close the draw if opened when the user touches elsewhere on the screen
draw.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
if(draw.isOpened())
((SlidingDrawer)v).animateOpen();
return false;
}});
//Open the draw by external button
((Button) findViewById(R.id.quiz_button)).setOnClickListener(
new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
draw.animateOpen();
} });
滑动绘制视图的 XML 是:
<SlidingDrawer android:layout_width="fill_parent" android:allowSingleTap="false" android:id="@+id/slidingDrawer1" android:content="@+id/content" android:handle="@+id/handle" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:layout_alignParentLeft="true">
<Button android:layout_height="wrap_content" android:layout_width="0px" android:visibility="invisible" android:text="Close" android:id="@+id/handle"></Button>
<LinearLayout android:id="@+id/content" android:gravity="center" android:background="#4FFFFF44" android:layout_width="fill_parent" android:layout_height="76dp"></LinearLayout>
</SlidingDrawer>
非常感谢山姆