transitionmanager被延迟

vlurs2pr  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(222)

我正在用java开发androidstudio,我对它很有经验,但是今天我遇到了这个问题,我想不通。我有一个屏幕,在上面我创建了一个可扩展的相对布局,下面有一个recyclerview。我的想法是,每当触摸顶部的relativelayout时,它的一个可扩展部分就会被设置为可见或消失,同时还有一个易于淡入/淡出的动画。在这个动画中,我希望recyclerview也能动画化,因为它被限制在它的底部。每当我第一次滚动recyclerview时,我的代码就会工作。否则,顶部菜单的动画将首先运行,然后是recyclerview,当这些项与菜单重叠时,会产生一个丑陋的用户体验。
以下是xml代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@android:color/white"
    tools:context=".ExercisesActivity">

    <RelativeLayout
        android:id="@+id/relLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/menu_black_top"
        android:paddingStart="30dp"
        android:paddingTop="24dp"
        android:paddingEnd="30dp"
        android:paddingBottom="24dp">

        <RelativeLayout
            android:id="@+id/relLayoutExtend"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/exercises_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:text="Exercises"
                android:textColor="@android:color/white"
                android:textSize="24sp"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/expand"
                android:layout_width="wrap_content"
                android:layout_height="8dp"
                android:layout_alignTop="@+id/exercises_tv"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="12dp"
                android:layout_marginEnd="6dp"
                app:srcCompat="@drawable/ic_expand" />

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/relLayout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/relLayoutExtend"
            android:layout_marginTop="16dp">

            <ImageView
                android:id="@+id/filter_img"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/search_img"
                android:layout_alignBottom="@+id/search_img"
                android:layout_alignParentEnd="true"
                app:srcCompat="@drawable/ic_filter" />

            <EditText
                android:id="@+id/exercises_et"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/search_img"
                android:layout_alignBottom="@+id/search_img"
                android:layout_marginStart="12dp"
                android:layout_marginEnd="40dp"
                android:layout_toStartOf="@+id/filter_img"
                android:layout_toEndOf="@+id/search_img"
                android:background="@null"
                android:hint="Lateral raise..."
                android:imeOptions="actionDone"
                android:inputType="textCapSentences"
                android:maxLines="1"
                android:singleLine="true"
                android:textColor="@android:color/white"
                android:textColorHint="@android:color/white" />

            <ImageView
                android:id="@+id/search_img"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                app:srcCompat="@drawable/ic_search" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@+id/exercises_et"
                android:layout_marginTop="6dp"
                android:layout_marginEnd="40dp"
                android:layout_toStartOf="@+id/filter_img"
                android:background="@android:color/white" />

        </RelativeLayout>

    </RelativeLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerViewFilter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relLayout1"
        android:layout_marginStart="12dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="12dp"
        android:fadingEdge="horizontal"
        android:fadingEdgeLength="14dp"
        android:orientation="horizontal"
        android:requiresFadingEdge="horizontal"
        android:scrollbars="none" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerViewExercises"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/recyclerViewFilter"
        android:paddingTop="16dp"
        android:fadingEdge="vertical"
        android:fadingEdgeLength="10dp"
        android:orientation="vertical"
        android:requiresFadingEdge="vertical"
        android:scrollbars="none" />

</RelativeLayout>

下面是java代码

private RelativeLayout mRelativeLayoutExpand, mRelativeLayoutSearch, mRelativeLayoutMenu;
    private RecyclerView recyclerViewExercises;

        mRelativeLayoutExpand = findViewById(R.id.relLayoutExtend);
        mRelativeLayoutSearch = findViewById(R.id.relLayout2);
        mRelativeLayoutMenu = findViewById(R.id.relLayout1);
        recyclerViewExercises = findViewById(R.id.recyclerViewExercises);

mRelativeLayoutExpand.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mRelativeLayoutSearch.getVisibility() == View.GONE) {
                TransitionManager.beginDelayedTransition(mRelativeLayoutMenu, new AutoTransition());
                TransitionManager.beginDelayedTransition(recyclerViewExercises, new AutoTransition());
                mRelativeLayoutSearch.setVisibility(View.VISIBLE);
            } else {
                TransitionManager.beginDelayedTransition(mRelativeLayoutMenu, new AutoTransition());
                TransitionManager.beginDelayedTransition(recyclerViewExercises, new AutoTransition());
                mRelativeLayoutSearch.setVisibility(View.GONE);
            }
        }
    });

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题