CardStackView icon indicating copy to clipboard operation
CardStackView copied to clipboard

ScrollView inside CardView that appear/disappear on itemView.onClick

Open Brijender opened this issue 5 years ago • 0 comments

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:-

<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>

Brijender avatar May 03 '20 07:05 Brijender