yuyakaido / CardStackView

📱Tinder like swipeable card view for Android
Apache License 2.0
2.36k stars 448 forks source link

ScrollView inside CardView that appear/disappear on itemView.onClick #314

Open Brijender opened 4 years ago

Brijender commented 4 years ago

How do you implement a ScrollView inside the CardView that appears/disappears on click. The idea is to show a long text on the CardView inside a ScrolllView.

I tried this inside onBindViewHolder() as mentioned below. The ScrollView becomes visible on a click and does not disappear on further clicks.

holder.itemView.setOnClickListener(view -> {
                if (((CardStackViewHolder)holder).scrollViewFrameLayout.getVisibility() == View.INVISIBLE)
                    ((CardStackViewHolder)holder).scrollViewFrameLayout.setVisibility(View.VISIBLE);
                else
                    ((CardStackViewHolder)holder).scrollViewFrameLayout.setVisibility(View.INVISIBLE);
            });

This is my CardView Layout:- <?xml version="1.0" encoding="utf-8"?> <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/selectableItemBackground" android:foreground="?attr/selectableItemBackground" app:cardBackgroundColor="@android:color/white" app:cardCornerRadius="8dp" app:cardPreventCornerOverlap="false" app:cardUseCompatPadding="true">

     <FrameLayout
        android:id="@+id/frame_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="invisible"
        android:layout_gravity="center">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">

            <TextView
                android:id="@+id/long_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center"
                android:textColor="@android:color/white"
                android:padding="18dp"/>

        </ScrollView>

    </FrameLayout>

</androidx.cardview.widget.CardView>