如何实现一个可见手柄DrawerLayout手柄、如何实现、DrawerLayout

2023-09-12 04:03:22 作者:戒烟戒酒戒爱情

我已经成功实施了NavigationDrawer我的应用程序。

I have successfully implemented a NavigationDrawer for my application.

我的应用程序显示打开屏幕的左边抽屉。

My app displays a drawer that opens on the left of the screen.

我的问题是我需要添加在左侧的按钮。这个按钮可能被点击或刷卡打开左边的抽屉。那我可以做的。

My problem is I need to add a button on the left. That button might be clicked or swiped to open the left drawer. That I can do.

但按钮应该是的样子那就是将溢出到屏幕抽屉的一部分。

But the button is supposed to look like it's a part of the drawer that would overflow into the screen.

这意味着该按钮应同时作为滑动抽屉打开和关闭。

That means the button should slide simultaneously as the drawer opens and closes.

闭合状态:

打开状态

我尝试添加该按钮左边抽屉的布局,但似乎你不能做的东西出现其边界以外,和抽屉会一直当你关闭它得到完全隐藏。

I tried adding the button into the left drawer's layout, but it seems you can't make stuff appear outside of its boundaries, and the drawer will always get completely hidden when you close it.

现在我想将它添加到一个按钮添加到主DrawerLayout并使其对准左边抽屉的权利......但没有运气...它看起来像一个DrawerLayout不能有两个以上孩子......

Now I'm trying adding it to add a button to the main DrawerLayout and make it align to the right of the left drawer... But no luck... It looks like a DrawerLayout can't have more than two children...

任何帮助将AP preciated。

Any help will be appreciated.

我使用的支持库(V4)

I'm using the Support library (v4)

而我支持API 8级。所以不能使用 ImageView.setTranslationX View.OnAttachStateChangeListener

And I am supporting API level 8... So can't use ImageView.setTranslationX or View.OnAttachStateChangeListener

推荐答案

我发现这样做pretty的轻松感谢写Mobistry(SO伪)

I found a way of doing this pretty easily thanks to the Aniqroid library written by Mobistry (SO pseudo)

我使用的是Android的SlidingDrawer的副本,但可以让你的抽屉里放置到屏幕的任何一个角落SlidingTray类。

I use the SlidingTray class which is a copy of android SlidingDrawer but lets you position the drawer to any corner of the screen.

我宣布通过XML元素

<com.sileria.android.view.SlidingTray 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="270dp"
    android:content="@+id/content"
    android:handle="@+id/handle" >

    <ImageView
        android:id="@+id/handle"
        android:layout_width="320dp"
        android:layout_height="24dp"
        android:background="@drawable/tray_btn" />

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="fill_vertical"
        android:orientation="vertical" >
    </LinearLayout>

</com.sileria.android.view.SlidingTray>

和刚刚打电话

Kit.init(this);

在我的主活动充气的布局了。

我感谢aniqroid开发者!

I thank aniqroid devs!

的https://$c$c.google.com/p/aniqroid/