【发布时间】:2015-11-07 20:24:33
【问题描述】:
我想创建一个导航抽屉效果,但不是抽屉从左侧滑出,它必须在主视图“后面”,所以滑动的项目是视图本身(即向右) - 抽屉根本不动,而是通过将主视图滑开来“显露”。手指滑动(并点击汉堡图标)动作与抽屉相同,只是显示效果不同。
主视图移动的方式和这里可以实现的一样
How to move main content with Drawer Layout left side
但在我的情况下,我希望“抽屉”静态保持在主视图下方。
我已经通过覆盖视图和使抽屉透明达到了预期的效果——当然这意味着抽屉不再用于导航;只是为了效果。使用上面链接中的代码
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/whole_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- everything here is now the new "drawer" -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="BOO I am hiding!"
android:id="@+id/tv2"
android:layout_gravity="left|top" />
<!-- /everything here is now the new "drawer" -->
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- The This is the main content frame -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="MOOOOOO!"
android:id="@+id/textView"
android:layout_gravity="left|top" />
</FrameLayout>
<!-- The see-through navigation drawer -->
<RelativeLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:id="@+id/left_drawer"
android:clickable="false"
android:background="@drawable/transparent_bg" <!-- #00FFFFFF -->
android:layout_gravity="start">
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
除了 id/tv2(或该层上的其他项目)在“抽屉”打开时不可点击之外,一切都很完美。
我试过了:
1) 使上面的布局不可点击(drawer_layout、content_frame和left_drawer setClickable(false)无效)。
2) 上面链接中的代码在 X 轴上移动 content_frame 而不是 drawyer_layout - 我尝试移动 drawyer_layout 而不是框架 - 这不能正常工作,因为您不能再单击最右侧以再次关闭抽屉。
3) 将drawer_layout的android:layout_width更改为fill_parent,但这仍然是一个问题,因为它不是被移开的层。
我的猜测是 DrawerLayout ( android.support.v4.widget.DrawerLayout ) 并不意味着在另一个布局之上,我可能需要创建自己的抽屉来达到预期的效果 - 任何想法或建议都会很棒。
【问题讨论】:
标签: android