【问题标题】:Toolbar and floating action button are not displaying properly工具栏和浮动操作按钮未正确显示
【发布时间】: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


【解决方案1】:

似乎工具栏被设计为“高于”所有其他视图。我遇到了同样的问题,只是在工具栏下方添加了一个视图以创建一些空间。这使工厂变得可见。

类似:

    <view
        android:layout_width="match_parent"
        android:layout_height="20dp"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 2016-11-09
    • 1970-01-01
    • 2022-06-25
    • 2016-06-19
    • 1970-01-01
    相关资源
    最近更新 更多