Эффект мерцания не работает в RecyclerView Android

Я пытаюсь включить эффект мерцания в представление ресайклера перед загрузкой изображений из firebase, но он показывает только точки в представлении ресайклера вместо изображений, прежде чем включение мерцающих изображений загружается правильно

Нет ошибок или предупреждений в журнале

Файлы Java

Search_Fragment.java // Поиск фрагмента

          public class Search_Fragment extends Fragment {
    public List<Upload> mUploads;
    PostAdapter postsAdapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_search, container, false);
        RecyclerView postRecyclerView = view.findViewById(R.id.postRecyclerView);
        ShimmerFrameLayout shimmerFrameLayout = view.findViewById(R.id.shimmerLayout);
        postRecyclerView.setLayoutManager(
                new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
        );
        mUploads = new ArrayList<>();
        postsAdapter = new PostAdapter(getContext(), mUploads);
        postRecyclerView.setAdapter(postsAdapter);
        getData();
        return view;
    }

    private void getData() {
        View view;
        Context context;
        ShimmerFrameLayout shimmerFrameLayout = new ShimmerFrameLayout(getContext());
        shimmerFrameLayout.findViewById(R.id.shimmerLayout);
        shimmerFrameLayout.startShimmer();
        DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("uploads");
        databaseReference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
                if (snapshot.exists()) {
                    for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
                        Upload upload = dataSnapshot.getValue(Upload.class);
                        mUploads.add(upload);
                        shimmerFrameLayout.stopShimmer();
                        shimmerFrameLayout.setVisibility(View.GONE);

                    }

                }

                //notify the adapter
                postsAdapter.notifyDataSetChanged();
            }

            @Override
            public void onCancelled(@NonNull DatabaseError error) {
            }
        });
    }

}

PostAdapter.java // класс адаптера

           public class PostAdapter extends RecyclerView.Adapter<PostAdapter.PostViewHolder> {
    public static List<Upload> mUploads;
    Context mcontext;


    public PostAdapter(Context context, List<Upload> uploads) {
        mUploads = uploads;
        mcontext = context;
    }


    @NonNull
    @Override
    public PostViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        view = LayoutInflater.from(mcontext).inflate(R.layout.post_item_container, parent, false);
        return new PostViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PostViewHolder holder, int position) {
        Upload uploadCurrent = mUploads.get(position);
        Shimmer shimmer = new Shimmer.ColorHighlightBuilder()
                .setBaseColor(Color.parseColor("#F3F3F3"))
                .setBaseAlpha(1)
                .setHighlightColor(Color.parseColor("#E7E7E7"))
                .setHighlightAlpha(1)
                .setDropoff(50)
                .build();
        ShimmerDrawable shimmerDrawable = new ShimmerDrawable();
        shimmerDrawable.setShimmer(shimmer);
        Glide.with(mcontext)
                .load(uploadCurrent.getmImageUrl())
                .diskCacheStrategy(DiskCacheStrategy.DATA)
                .preload();
        Glide.with(mcontext)
                .load(uploadCurrent.getmImageUrl())
                .diskCacheStrategy(DiskCacheStrategy.DATA)
                .placeholder(shimmerDrawable)
                .into(holder.imageView);


    }

    @Override
    public int getItemCount() {
        return mUploads.size();
    }

    public static class PostViewHolder extends RecyclerView.ViewHolder {
        ShapeableImageView imageView;

        PostViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.imagePost);
        }

    }
}

XML файлы

fragment_search.xml

           <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/search_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black">

    <androidx.appcompat.widget.SearchView
        android:id="@+id/search_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginStart="15dp"
        android:layout_marginTop="15dp"
        android:layout_marginEnd="15dp"
        android:layout_marginBottom="15dp"
        android:background="@color/grey" />

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:overScrollMode="always"
        android:layout_below="@+id/search_view">

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/listText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="20dp"
                android:paddingStart="40dp"
                android:paddingEnd="0dp"
                android:text="@string/today_s_most_liked_posts"
                android:textColor="@color/white"
                android:textSize="25sp"
                android:textStyle="italic" />
            <com.facebook.shimmer.ShimmerFrameLayout
                android:id="@+id/shimmerLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <include
                        layout="@layout/post_item_container_shimmer"/>
                    <include
                        layout="@layout/post_item_container_shimmer"/>
                    <include
                        layout="@layout/post_item_container_shimmer"/>
                    <include
                        layout="@layout/post_item_container_shimmer"/>
                    <include
                        layout="@layout/post_item_container_shimmer"/>
                    <include
                        layout="@layout/post_item_container_shimmer"/>
                    <include
                        layout="@layout/post_item_container_shimmer"/>
                    <include
                        layout="@layout/post_item_container_shimmer"/>
                    <include
                        layout="@layout/post_item_container_shimmer"/>
                    <include
                        layout="@layout/post_item_container_shimmer"/>

                </LinearLayout>

            </com.facebook.shimmer.ShimmerFrameLayout>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/postRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />

        </LinearLayout>

    </androidx.core.widget.NestedScrollView>

</RelativeLayout>

post_item_container.xml

      <com.google.android.material.imageview.ShapeableImageView xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:id="@+id/imagePost"
    android:layout_marginStart="11dp"
    android:layout_marginTop="11dp"
    android:layout_width="match_parent"
    app:shapeAppearanceOverlay="@style/RoundedCorner"
    android:contentDescription="@string/todo" />

post_item_containe_shimmer.xml

       <com.google.android.material.imageview.ShapeableImageView 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="wrap_content"
    android:id="@+id/imageShimmer"
    android:layout_marginStart="11dp"
    android:layout_marginTop="11dp"
    android:contentDescription="@string/todo"
    app:shapeAppearanceOverlay="@style/RoundedCorner" />

0 ответов

Другие вопросы по тегам