我有一个带协调器布局的应用程序,它在协调器布局中使用滑动选项卡和视图寻呼机。我试图在工具栏下面放置一个活动(列表)。我尝试了很多不同的东西,但总是列表与工具栏重叠。
布局
<?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>
答案 0 :(得分:23)
只需将 { "_id" : "sport", "count" : 2 }
{ "_id" : "shopping", "count" : 1 }
{ "_id" : "politics", "count" : 1 }
添加到需要位于工具栏
答案 1 :(得分:3)
请试试这个:
<?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
祝你好运答案 2 :(得分:1)
您可以使用LinearLayout替换CoordinatorLayout(使用android:orientation =“vertical”)。
<RelativeLayout>
<LinearLayout> (replaces the coordinator layout>
<AppBarLayout/>
<FrameLayout/>
</LinearLayout>
<FloatingActionButton/>
</RelativeLayout>