[英]Coordinator layout, activity below toolbar
我有一個帶協調器布局的應用程序,它使用協調器布局中的滑動選項卡和視圖尋呼機。 我試圖在工具欄下面放置一個活動(列表)。 我嘗試了很多不同的東西,但總是列表與工具欄重疊。
布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".MainActivity">
<LinearLayout 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="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
android:padding="2dp"
app:titleMarginStart="20dp"
android:theme="@style/AppTheme.AppBarOverlay"/>
<com.passwordstore.utility.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary" />
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@android:color/white"
android:foreground="@drawable/shadow"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</LinearLayout>
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" android:id="@+id/frameLayout">
<include layout="@layout/activity_password_list" />
</FrameLayout>
<android.support.design.widget.FloatingActionButton android:id="@+id/fabNew"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin" android:src="@drawable/ic_add_white_24dp"
app:layout_anchor="@+id/pager"
app:layout_anchorGravity="bottom|right|end"/>
</android.support.design.widget.CoordinatorLayout>
只需將app:layout_behavior="@string/appbar_scrolling_view_behavior"
到需要位於工具欄下的布局
請試試這個:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
android:padding="2dp"
app:titleMarginStart="20dp"
android:theme="@style/AppTheme.AppBarOverlay"/>
<com.passwordstore.utility.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary" />
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@android:color/white"
android:foreground="@drawable/shadow"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
</android.support.design.widget.AppBarLayout>
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_below= "@id/appbar"
app:layout_behavior="@string/appbar_scrolling_view_behavior" android:id="@+id/frameLayout">
<include layout="@layout/activity_password_list" />
</FrameLayout>
<android.support.design.widget.FloatingActionButton android:id="@+id/fabNew"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin" android:src="@drawable/ic_add_white_24dp"
app:layout_anchor="@+id/pager"
app:layout_anchorGravity="bottom|right|end"/>
</android.support.design.widget.CoordinatorLayout>
我刪除了linearLayout並將其替換為appBarLayout ,在你的Framelayout中添加了android: layout_below
祝好運
您可以使用LinearLayout替換CoordinatorLayout(使用android:orientation =“vertical”)。
<RelativeLayout>
<LinearLayout> (replaces the coordinator layout>
<AppBarLayout/>
<FrameLayout/>
</LinearLayout>
<FloatingActionButton/>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.