【问题标题】:Android LinearLayout inside AppbarLayoutAppbarLayout内的Android LinearLayout
【发布时间】:2017-05-11 23:57:36
【问题描述】:

我有一个appBarLayout 和一个collapsingToolbar。我想在collapsingToolbar 下方添加一个线性布局,它将与appBarLayout 一起滚动。我添加了app:layout_scrollFlags="scroll",但似乎不起作用。我错过了什么还是不可能?

代码如下:

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

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/white"
            android:orientation="vertical"
            app:layout_collapseMode="none"
            app:layout_collapseParallaxMultiplier="0.3">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="180dp"
                android:scaleType="centerCrop"/>
        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/tool_bar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"/>
    </android.support.design.widget.CollapsingToolbarLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll">
        ...
    </LinearLayout>
</android.support.design.widget.AppBarLayout>

here's the image

【问题讨论】:

  • 你是要让线性布局也消失还是只显示在appBar下方?

标签: android android-linearlayout android-appbarlayout android-collapsingtoolbarlayout


【解决方案1】:

嗨,迈克尔,您的道路正确,只需稍作改动,将这段代码复制粘贴到工作室中并尝试。

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

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/white"
            android:orientation="vertical"
            app:layout_collapseMode="none"
            app:layout_collapseParallaxMultiplier="0.3">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="180dp"
                android:scaleType="centerCrop"/>
        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/tool_bar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"/>

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

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

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="@dimen/activity_horizontal_margin" >
                <!-- Your content here -->
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

    </android.support.design.widget.CoordinatorLayout>

这是一个例子,http://www.androidauthority.com/using-coordinatorlayout-android-apps-703720/ 希望它对你有所帮助。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多