Как расширить CardView, чтобы перекрывать следующий элемент RecyclerView? - PullRequest
0 голосов
/ 17 июня 2019

У меня есть RecyclerView, который раздувает CardView с помощью пользовательского LinearLayoutManager, в котором прокрутка отключена.Я всегда буду отображать только 2 CardView на экране.У каждого CardView есть свернутая часть, которая появляется при нажатии маленькой стрелки.

Проблема: следующая карта нажата

Что мне нужно: в верхней части CardView свернутая часть должна перекрывать нижнюю часть CardView.У меня уже есть анимация, чтобы расширить его.В нижней части я хочу перекрыть изображение на верхнем CardView.Кроме того, другие невидимые CardViews никогда не должны появляться в процессе.Как мне этого добиться?

Вот мой CardView:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        card_view:cardElevation="8dp"
        card_view:cardCornerRadius="4dp">


    <androidx.constraintlayout.widget.ConstraintLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent">

        <!--*************visible part****************************-->

        <ImageView
                android:id="@+id/clash_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                card_view:layout_constraintTop_toTopOf="parent"
                card_view:layout_constraintBottom_toTopOf="@id/tv1"
                android:src="@drawable/image_placeholder" card_view:layout_constraintEnd_toEndOf="parent"
                card_view:layout_constraintStart_toStartOf="parent"
                />

        <TextView android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:paddingLeft="5dp"
                  android:paddingRight="5dp"
                  android:text="#Hashtag1"
                    android:id="@+id/tv1"
                card_view:layout_constraintTop_toBottomOf="@+id/clash_image"
                card_view:layout_constraintStart_toStartOf="parent"/>
        <TextView android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:paddingLeft="5dp"
                  android:paddingRight="5dp"
                  android:text="#Hashtag1"
                  android:id="@+id/tv2"
                card_view:layout_constraintStart_toEndOf="@+id/tv1"
                card_view:layout_constraintTop_toBottomOf="@+id/clash_image"/>
        <TextView android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:paddingLeft="5dp"
                  android:paddingRight="5dp"
                  android:text="#Hashtag1"
                  android:id="@+id/tv3"
                  card_view:layout_constraintStart_toEndOf="@+id/tv2"
                  card_view:layout_constraintTop_toBottomOf="@+id/clash_image"/>

        <ImageView
                android:id="@+id/expand"
                android:src="@drawable/ic_expand"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                card_view:layout_constraintEnd_toEndOf="parent"
                card_view:layout_constraintTop_toBottomOf="@+id/clash_image"/>


        <!--*****************invisible part to expand on click****************************-->


        <RelativeLayout
                android:id="@+id/rlCollapsingPart"
                android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        card_view:layout_constraintTop_toBottomOf="@+id/expand"
                        card_view:layout_constraintStart_toStartOf="parent"
        android:visibility="gone">

            <de.hdodenhof.circleimageview.CircleImageView
                    android:id="@+id/avatarThumbnail"
                    style="@style/icon"
                    android:src="@drawable/defaultavatar"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"/>

            <TextView
                    android:id="@+id/username_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    tools:text="willsmith"
                    android:textColor="@color/black"
                    android:textStyle="bold"
                    android:layout_toEndOf="@+id/avatarThumbnail"
            />



            <TextView
                    android:id="@+id/caption_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingStart="10dp"
                    android:textColor="@color/black"
                    android:layout_alignParentStart="true"
                    android:layout_below="@+id/avatarThumbnail"
                    tools:text="willsmith This is a caption for the post. It's actually a very long caption."/>


            <RelativeLayout android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/caption_text"
            android:background="@color/grey">

                <ImageView
                        android:id="@+id/like_image"
                        android:layout_height="45dp"
                        android:layout_width="45dp"
                        android:padding="10dp"
                        android:src="@drawable/ic_home"
                        android:layout_alignParentStart="true"/>

                <ImageView
                        android:id="@+id/comment_image"
                        card_view:layout_constraintStart_toEndOf="@id/like_image"
                        card_view:layout_constraintTop_toTopOf="@id/like_image"
                        card_view:layout_constraintBottom_toBottomOf="@id/like_image"
                        android:layout_height="45dp"
                        android:layout_width="45dp"
                        android:padding="10dp"
                        android:src="@drawable/ic_home"
                        android:layout_toEndOf="@+id/like_image"/>

                <ImageView
                        android:id="@+id/share_image"
                        android:layout_toEndOf="@+id/comment_image"
                        android:layout_height="45dp"
                        android:layout_width="45dp"
                        android:padding="10dp"
                        android:src="@drawable/ic_home"/>

                <ImageView
                        android:id="@+id/more_image"
                        style="@style/icon"
                        android:src="@drawable/ic_home"
                        android:layout_alignParentEnd="true"/>

            </RelativeLayout>

        </RelativeLayout>





    </androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.material.card.MaterialCardView>

РЕДАКТИРОВАТЬ

Я раскрываю скрытую часть, используя базовый приемник при нажатиив моем адаптере и аниме. Adapter.kt

override fun onBindViewHolder(holder: ViewHolder, position: Int) {

...         

holder.view.expand.setOnClickListener(View.OnClickListener {
        val slideDown = AnimationUtils.loadAnimation(context, R.anim.card_expand_animator)
        //toggling visibility
        if(holder.view.rlCollapsingPart.visibility == View.VISIBLE) {
            holder.view.rlCollapsingPart.visibility = View.GONE
        }else{
            holder.view.rlCollapsingPart.startAnimation(slideDown)
            holder.view.rlCollapsingPart.visibility = View.VISIBLE    
        }
    })  

}

MyAnim.xml (в папке anim)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <scale
            android:duration="500"
            android:fromXScale="1.0"
            android:fromYScale="0.0"
            android:toXScale="1.0"
            android:toYScale="1.0"/>
</set>

normal state

expanded state

1 Ответ

0 голосов
/ 18 июня 2019

После дальнейших исследований и понимания, это невозможно как есть. Чтобы «перекрыть» другую карту, мне нужно накачать новую раскладку, используя PupUpWindow, которая может выглядеть гладко, используя принцип Shared Element. В противном случае LayoutManager всегда будет толкать другую карту вниз. На данный момент я выбрал более простое решение, которое заключается в расширении скрытой части по направлению к вершине, чтобы покрыть изображение Card.

...