Развернуть и скрыть Layout Android

Мне нужно запрограммировать эту анимацию https://i.stack.imgur.com/02FtY.gif в макет ограничения, который имел текст редактирования и вид переработчика внутри, как на картинке

введите здесь описание изображения

и у меня нет никакой идеи, чтобы достичь этого.

может кто-нибудь помочь мне с некоторыми идеями?


person Murillo Minuscoli Maciel    schedule 18.12.2020    source источник
comment
Я думаю, вам нужен CoordinatorLayout, посмотрите, поможет ли это: stackoverflow.com/questions/34978250/   -  person Quinn    schedule 18.12.2020


Ответы (2)


Вы можете использовать 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, если вы ее скрываете.

person Estid Felipe Lozano Reyes    schedule 18.12.2020

Вы можете сделать это с помощью 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>
person Zain    schedule 19.12.2020