【发布时间】:2016-07-21 10:01:46
【问题描述】:
我创建了一个在片段中使用的具有视差效果的布局。
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/collapsingImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/baner_1"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!--OTHER SCROLABLE STUFF-->
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
只要 Fragment 在 Activity 的根目录(到 container_main)中膨胀,它就可以正常工作。
所以Activity的布局是这样的:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>
现在我想在我的 Activity 中添加一个 DrawerLayout,这就是我卡住的地方。
我通过添加 DrawerLayout 更改了 Activity 的布局。
然后将上面提到的 Fragment 膨胀为相同的container_main,但视差和NestedScrollView 都不再起作用了。
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/container_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
</FrameLayout>
<ListView
android:id="@+id/drawerListView"
android:layout_width="@dimen/drawer_width"
android:layout_height="match_parent"
/>
</android.support.v4.widget.DrawerLayout>
使用 DrawerLayout 和折叠工具栏的技巧和方法在哪里?
【问题讨论】:
-
想要添加导航?
-
是的,我需要导航
-
可能是你忘了给 listview 提供重力:android:layout_gravity="start"
-
好的,然后在你的项目中添加导航抽屉活动,然后编辑它们,
-
谢谢,瑞腾。我不敢相信,但这就是原因!
标签: android android-layout android-toolbar drawerlayout android-collapsingtoolbarlayout