n_r
n_r

Reputation: 639

How to remove shimmer effect from a child view in Facebook Shimmer

I have a shimmer layout with multiple views. For one of these views, a TextView, I want to prevent the shimmer effect on only the TextView. Is there any unbuilt function for this or do I need to create multiple views.

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.facebook.shimmer.ShimmerFrameLayout
            android:id="@+id/shimmerParent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:shimmer_auto_start="true">

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

                <cImageView
                    android:id="@+id/shimmerNudgeBg"
                    android:layout_width="@dimen/touch_constraints"
                    android:layout_height="113dp"
                    android:src="@drawable/some_bg"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <View
                    android:id="@+id/shimmerTitle"
                    android:layout_width="148dp"
                    android:layout_height="23dp"
                    android:layout_margin="16dp"
                    android:background="@drawable/shimmer_10_dp"
                    app:layout_constraintStart_toStartOf="@id/shimmerNudgeBg"
                    app:layout_constraintTop_toTopOf="@id/shimmerNudgeBg" />

                <View
                    android:layout_width="160dp"
                    android:layout_height="16dp"
                    android:layout_marginTop="4dp"
                    android:background="@drawable/shimmer_10_dp"
                    app:layout_constraintStart_toStartOf="@id/shimmerTitle"
                    app:layout_constraintTop_toBottomOf="@id/shimmerTitle" />

                <View
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:layout_margin="16dp"
                    android:background="@drawable/shimmer_10_dp"
                    app:layout_constraintEnd_toEndOf="@id/shimmerNudgeBg"
                    app:layout_constraintTop_toTopOf="@id/shimmerNudgeBg" />

                <View
                    android:layout_width="135dp"
                    android:layout_height="12dp"
                    android:layout_marginBottom="16dp"
                    android:background="@drawable/shimmer_10_dp"
                    app:layout_constraintBottom_toBottomOf="@id/shimmerNudgeBg"
                    app:layout_constraintStart_toStartOf="@id/shimmerTitle" />

                // Don't want this to have shimmer effect
                <TextView 
                    android:id="@+id/title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="32dp"
                    android:text="@string/zc_past_statements"
                    android:textAppearance="@style/SomeTextStyle"
                    android:textColor="@color/black_22"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/shimmerNudgeBg"
                    app:shimmer_auto_start="false" />

                <include
                    android:id="@+id/includeShimmerRv"
                    layout="@layout/someLayout"
                    android:layout_width="@dimen/touch_constraints"
                    android:layout_height="wrap_content"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/title" />
            </androidx.constraintlayout.widget.ConstraintLayout>
        </com.facebook.shimmer.ShimmerFrameLayout>
    </FrameLayout>
</layout>

I am trying to avoid having multiple groups with ShimmerFrameLayout, and this way I can directly use the use view as a reference to create a shimmer, is there an easy way to do this?

Upvotes: 1

Views: 127

Answers (0)

Related Questions