我在使用普通按钮并将AppBarLayout设置为该按钮的锚点时遇到问题,因为Button的上部位于AppBarLayout下。当使用FloatingActionButton
且我尝试设置高程并使用bringToFront
时,它可以工作,但没有任何作用。
<?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="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/materialup.appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/materialup.toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="enterAlways|snap"
style="@style/ToolBarWithNavigationBack"
/>
<LinearLayout
android:id="@+id/materialup.title_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="30dp"
android:orientation="vertical"
android:paddingTop="8dp"
android:gravity="center"
app:layout_scrollFlags="scroll|enterAlways|snap">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:text="@string/title_mup_name"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
android:text="@string/subtitle_mup"
android:textColor="@android:color/white"
/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/materialup.viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
<Button
android:id="@+id/btn_submit_trip"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="@+id/materialup.appbar"
app:layout_anchorGravity="bottom|center_horizontal"
android:text="Submit"
/>
</android.support.design.widget.CoordinatorLayout>
您可以尝试两种可能的解决方案:首先尝试从应用程序栏中的线性布局中删除padding_bottom,同样,您将最小化应用程序栏的表面以使按钮出现。第二个添加android:layout_marginTop到您的按钮。让我知道是否可行,否则,我们可以搜索其他选项。
将您的提交按钮包装在Cardview内,然后将海拔高度设置为Cardview。会的。我使用了textview而不是按钮:
<androidx.cardview.widget.CardView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:cardElevation="4dp"
app:layout_anchor="@+id/materialup.appbar"
app:layout_anchorGravity="bottom|center_horizontal">
<TextView
android:id="@+id/btn_submit_trip"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="12dp"
android:text="Submit"
android:textStyle="bold"/>
</androidx.cardview.widget.CardView>