简体   繁体   English

展开和隐藏布局 Android

[英]Expand and hide Layout Android

I need to program this animation https://i.stack.imgur.com/02FtY.gif into a constraint layout that had an edit text and a recycler view inside like the picture我需要将此 animation https://i.stack.imgur.com/02FtY.gif 编程到一个约束布局中,其中有一个编辑文本和一个像图片一样的回收器视图

在此处输入图像描述

and I dont have any idea to achive this.我没有任何想法来实现这一点。

can someone help me with some ideas?有人可以帮我一些想法吗?

You can use ObjectAnimator to move your bar up and down.您可以使用ObjectAnimator上下移动栏。 Up to hide it in top and down to show it from top.向上隐藏它在顶部和向下显示它从顶部。

Example:例子:

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();
}

This function should works for you, only pass it true if you are showing the bar, and false if you are hiding it.这个 function 应该适合你,只有在显示栏时才传递true ,如果隐藏则传递false

You can do that with CoordinatorLayout你可以用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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM