android - LinearLayout 重叠支持 CoordinatorLayout

标签 android android-layout material-design

我是第一次使用 CoordinatorLayout,我不太了解它是如何工作的。

我的 LinearLayout 与我的工具栏重叠,就好像我在 FrameLayout 或 RelativeLayout 中一样,我不知道如何告诉它到下面(比如 android:layout_below 和 RelativeLayout )

这是我的代码:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="192dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:src="@drawable/logo2"
                app:layout_collapseMode="pin" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/appbar"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">

            .... Very Large Form ...
    </LinearLayout>
</android.support.design.widget.CoordinatorLayout>

另一个疑惑:我看到的例子几乎都是用CoordinateLayout管理RecyclerView的。 我的布局不是 RecyclerView,只是一个很长的表格。这样做有意义吗?

最佳答案

尝试将您的内容嵌套在 NestedScrollView 中。不要忘记包含 layout_behavior XML 标记。

 <android.support.v4.widget.NestedScrollView
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         app:layout_behavior="@string/appbar_scrolling_view_behavior">

     <!-- Your scrolling content -->

 </android.support.v4.widget.NestedScrollView>

其他资源: http://developer.android.com/reference/android/support/design/widget/AppBarLayout.html

关于android - LinearLayout 重叠支持 CoordinatorLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30940698/

相关文章:

android - 为什么当我更改 Button 中的文本大小时,相邻的 Button 会移动

android - ActionBarSherlock 错误膨胀类

flutter - 如何在 Flutter 中为禁用的文本表单字段标签设置主题颜色?

android - 解析.com : JSONObject cannot be cast to ParseFile

Android:如何创建具有填充整个屏幕的特定列和行的网格布局

android - NDK 11 链接器将警告视为错误

java - Activity/fragment 转换是否与 Lollipop 之前的设备兼容?

android - Circular Reveal Android Compat With Design Library 28

java - 在 Activity 之间传递加速度计值 - 应用程序崩溃

android - 与前台服务android通信