【问题标题】:Hiding the sliding drawer handle隐藏滑动抽屉把手
【发布时间】:2011-12-01 10:14:34
【问题描述】:

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

非常感谢 山姆

【问题讨论】:

  • 尝试将Buttonlayout_widht设置为0px
  • 在这种情况下,我们如何启用SlidingDrawer的滑动功能呢?我也在尝试同样的事情。但是如果禁用该按钮,我的滑动操作不适用于内容。如果您有任何解决方案,请告诉我。
  • 嗨 Raj,很长时间了,因为我接触了 android,但是一旦我再次找到它,我会在这里发布我的解决方案!
  • 嗨 Raj,我在问题帖子中为您发布了答案。让我知道事情的后续!它还具有附加功能,如果您在非常方便的地方点击其他地方,抽奖会自行关闭

标签: java android android-layout android-widget slidingdrawer


【解决方案1】:

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

在onLayout方法中找到该行

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

并将其更改为

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

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

【讨论】:

    【解决方案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 中可以正常工作。

    希望有所帮助:)

    【讨论】:

      【解决方案3】:

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

              <ImageButton
                  android:id="@+id/cash_menuGruop_handle"
                  style="?android:attr/buttonStyleSmall"
                  android:layout_width="wrap_contetn"
                  android:layout_height="0dp"/>
      

      【讨论】:

        【解决方案4】:
          <Button 
                android:layout_width="0dp" 
                android:layout_height="0dp" 
                android:id="@+id/handle"
                android:visibility="gone" //DOES NOT WORK
                </Button>
        
        1. 使用高度和宽度 0dp ,用于打开和关闭使用 handle.performclick(); 它对我有用

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-12-04
          相关资源
          最近更新 更多