【问题标题】:Expand and hide Layout Android展开和隐藏布局 Android
【发布时间】:2021-03-29 11:02:29
【问题描述】:

我需要编写这个动画 https://i.stack.imgur.com/02FtY.gif 进入一个约束布局,里面有一个编辑文本和一个像图片一样的回收器视图

我没有任何想法来实现这一点。

有人可以帮我出点主意吗?

【问题讨论】:

标签: android xml android-animation android-motionlayout


【解决方案1】:

您可以使用ObjectAnimator 上下移动条形图。向上隐藏在顶部,向下从顶部显示。

例子:

float viewHeight = 100f;
float durationInMs = 1000;

private void animTranslateY(boolean show) {
    float translationY = show ? viewHeight : - viewHeight;
    ObjectAnimator animation = ObjectAnimator.ofFloat(view, "translationY", translationY);
    animation.setDuration(durationInMs);
    animation.start();
}

这个函数应该对你有用,如果你显示栏只传递它true,如果你隐藏它,传递false

【讨论】:

    【解决方案2】:

    你可以用CoordinatorLayout做到这一点

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.coordinatorlayout.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">
    
        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlways">
    
                <androidx.appcompat.widget.SearchView
                    android:id="@+id/searchview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:iconifiedByDefault="false"
                    android:queryHint="@string/query_hint"
                    app:iconifiedByDefault="false"
                    app:queryHint="@string/query_hint" />
    
            </com.google.android.material.appbar.CollapsingToolbarLayout>
    
        </com.google.android.material.appbar.AppBarLayout>
    
        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
    
    </androidx.coordinatorlayout.widget.CoordinatorLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 2018-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多