我希望ImageView位于我的工具栏和内容之间(带内容的布局)。 工具栏无法展开。
我怎样才能做到这一点?
我是这样做的:
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:titleTextAppearance="@style/AppTheme.ToolbarText" />
</android.support.design.widget.AppBarLayout>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<android.support.percent.PercentRelativeLayout
android:id="@+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/advantages_background"
app:layout_heightPercent="100%">
....
</android.support.percent.PercentRelativeLayout>
</android.support.percent.PercentRelativeLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/appBarLayout"
app:layout_anchorGravity="bottom|center">
<ImageView
android:id="@+id/fab"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/advantages_circle" />
...
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
我得到了这个(工具栏与我的圆圈重叠):
我该如何解决?
我希望ImageView(我的FrameLayout)重叠工具栏(锚点)
答案 0 :(得分:5)
将此行添加到framlayout
android:elevation="20dp"
答案 1 :(得分:2)
将app:layout_behavior="@string/appbar_scrolling_view_behavior"
添加到FrameLayout
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<android.support.percent.PercentRelativeLayout
android:id="@+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_dark"
app:layout_heightPercent="100%" />
</android.support.percent.PercentRelativeLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/appBarLayout"
app:layout_anchorGravity="bottom|center"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ImageView
android:id="@+id/fab"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@mipmap/ic_launcher" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
如果您想要重叠到工具栏中,请添加app:behavior_overlapTop="20dp"
答案 2 :(得分:1)
如果您将AppBarLayout更改为FrameLayout
,这将有效<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:titleTextAppearance="@style/AppTheme.ToolbarText" />
</FrameLayout>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<android.support.percent.PercentRelativeLayout
android:id="@+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/advantages_background"
app:layout_heightPercent="100%">
....
</android.support.percent.PercentRelativeLayout>
</android.support.percent.PercentRelativeLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/appBarLayout"
app:layout_anchorGravity="bottom|center">
<ImageView
android:id="@+id/fab"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/advantages_circle" />
...
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
答案 3 :(得分:0)
添加android:margineTop =&#34;?attr / actionBarSize&#34;在你的framlayout。