【发布时间】:2017-06-11 23:39:03
【问题描述】:
我希望我的布局看起来像 this (design preview in Android Studio).
遗憾的是,当我在调试模式下运行应用程序时,我的模拟器上会显示以下内容(just half of the toolbar is visible and the fab not at all)。
虽然我在layout.xml 文件中应用了app:layout_scrollFlags="scroll|enterAlways",但我的Toolbar 也固定在顶部。
layout.xml
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:id="@+id/imageview_main"
android:scaleType="fitXY"
android:src="@drawable/test"
android:layout_height="match_parent"
android:layout_weight="0.3"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerview"
android:layout_weight="0.7">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_camera"
app:borderWidth="0dp"
android:layout_marginRight="15dp"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end" />
任何帮助将不胜感激。
【问题讨论】:
-
尝试从
AppBarLayout中删除android:fitsSystemWindows="true" -
工具栏现在完全显示,但浮动操作按钮仍然缺失,提前感谢@Lamorak
标签: android android-layout android-toolbar floating-action-button