我正在使用滑动抽屉小部件在 Android 应用程序中构建 View 。我已经实现了自己的自定义 handle (只是一行菜单按钮,然后更改抽屉的内容,然后激活 openAmination)。我已设法禁用滑动抽屉附带的标准 handle ,但我想完全删除它。
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 并执行相同的操作,但也不起作用。
View h = findViewById(R.id.handle);
h.setVisibility(View.GONE);
然后我尝试扩展 slipDrawer 类并制作自己的类,但它仍然需要一个句柄!。我是否有一个没有默认 handle 的滑动抽屉?
-----解决方案----
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();
} });
滑动绘制 View 的 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>
<小时/>
非常感谢 山姆
最佳答案
我尝试了很多个小时,但未能摆脱 handle ,我能做的最好的事情就是将其移离 window 较远。如果您已经扩展了 slipdrawer 类,那么这应该很容易。
在 onLayout 方法中找到该行
handle.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
并将其更改为
handle.layout(10000, 10000, 10000, 10000);
基本上,它只是将其位置设置为屏幕的方式。
关于java - 隐藏滑动抽屉 Handlebars ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8339638/