0

我正在使用滑动抽屉小部件在我的 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>

非常感谢山姆

4

4 回答 4

2

我找到了解决问题的更好方法。

不要隐藏句柄本身,但它是内容。我有一个 ImageView 作为句柄,但我将其更改为一个包含 ImageView 的 LinearLayout。

<LinearLayout
    android:id="@id/handle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/handleImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/sliding_drawer_handle" />
</LinearLayout>

现在 handleImage.setVisibility(View.INVISIBLE) 在 onAnimationEnd 中工作正常。

希望有帮助:)

于 2012-09-10T08:24:59.757 回答
2

我试了好几个小时都没能摆脱把手,我能做的最好的就是把它从视窗移开。如果您已经扩展了slidingdrawer 类,它应该很容易。

在 onLayout 方法中找到该行

handle.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);

并将其更改为

handle.layout(10000, 10000, 10000, 10000);

基本上它只是将其位置设置为屏幕方式。

于 2011-12-01T10:50:47.557 回答
1

我有同样的问题,我不想显示手柄,因为我有一个个人按钮,可以在单击时显示 SlidingDrawer。所以,我解决了将手柄高度设置为 0dp 的问题。这是我的句柄代码:

        <ImageButton
            android:id="@+id/cash_menuGruop_handle"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_contetn"
            android:layout_height="0dp"/>
于 2013-08-29T09:54:05.467 回答
0
  <Button 
        android:layout_width="0dp" 
        android:layout_height="0dp" 
        android:id="@+id/handle"
        android:visibility="gone" //DOES NOT WORK
        </Button>
  1. 使用高度和宽度 0dp ,打开和关闭使用 handle.performclick(); 它对我有用
于 2017-05-18T07:51:12.977 回答