【问题标题】:Hiding middle view first in coordinator layout在协调器布局中首先隐藏中间视图
【发布时间】:2017-04-19 05:09:19
【问题描述】:

我的布局如下

  • 布局1
  • 布局2
  • 滚动视图

滚动时,我需要先消失 Layout2,然后再消失 Layout1。例如看下面的 gif 中间视图先消失,然后顶部视图消失。我怀疑我需要一些自定义行为代码,但不知道从哪里开始。

这是我当前的 xml

<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="com.example.chamoda.coordinatelayoutdemo.ScrollingActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="180dp"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="90dp"
        android:background="@color/colorAccent"
        app:layout_scrollFlags="scroll" >

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="90dp"
        android:background="@color/colorPrimary"
        app:layout_scrollFlags="scroll" >

    </LinearLayout>

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

<android.support.v4.widget.NestedScrollView 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.chamoda.coordinatelayoutdemo.ScrollingActivity"
    tools:showIn="@layout/activity_scrolling">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/text_margin"
        android:text="@string/large_text" />

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

如何使用坐标布局归档该动画?

【问题讨论】:

  • 遇到了同样的问题。你解决了吗?

标签: android android-animation android-coordinatorlayout


【解决方案1】:

您可以使用CollapsingToolbarLayoutToolbar 来制作它。 请参阅这个很棒的教程以获取更多信息:

https://inthecheesefactory.com/blog/android-design-support-library-codelab/en

【讨论】:

  • 谢谢,但我找不到任何对我的确切用例有帮助的东西。我在 CollapsingToolbarLayout 中找到的每个用例都会首先移动顶部布局。可能是我错过了什么?
猜你喜欢
  • 2016-07-26
  • 1970-01-01
  • 2019-05-17
  • 1970-01-01
  • 2016-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多