簡體   English   中英

Glide 4.7.1 占位符未加載

[英]Glide 4.7.1 placeholder not loading

我正在嘗試使用 GlideLibrary 加載占位符圖像,我正在使用 SimpleTarget。 占位符圖像未加載,但 url 中的圖像正在加載。 我已經搜索了很多並使用了 RequestOptions。 盡管如此,它似乎不起作用。

下面是代碼:

Glide.with(mContext).load("https://i.imgur.com/0k7ZFWr.png").apply(RequestOptions.placeholderOf(R.drawable.pubgguide_icon)).into(new SimpleTarget<Drawable>() {
        @Override
        public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                holder.cardImageLayout.setBackground(resource);
                Drawable cardViewBackground = holder.cardImageLayout.getBackground();
                cardViewBackground.setColorFilter(0x5F000000, PorterDuff.Mode.SRC_ATOP);
            }
        }
    });

我正在使用 Glide 庫 4.7.1。 我也嘗試過使用 setDefaultRequestOptions() - 不起作用。

我的卡片視圖 XML:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/category_cardview"
        android:layout_width="match_parent"
        android:layout_height="220dp"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="@dimen/leftrightmargin"
        android:layout_marginRight="@dimen/leftrightmargin"
        android:layout_marginTop="10dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="4dp"
                android:layout_height="match_parent"
                android:background="#FFBF41"></LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <LinearLayout
                    android:id="@+id/cardImageLayout"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="2">


                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginBottom="3dp"
                        android:layout_marginLeft="@dimen/leftrightmargin"
                        android:layout_marginRight="@dimen/leftrightmargin"
                        android:layout_marginTop="60dp"
                        android:orientation="vertical">

                        <TextView
                            android:id="@+id/category_name"
                            android:layout_width="match_parent"
                            android:layout_height="0dp"
                            android:layout_gravity="bottom"
                            android:layout_weight="1"
                            android:gravity="bottom"
                            android:paddingLeft="5dp"
                            android:shadowColor="#f3848383"
                            android:shadowDx="4"
                            android:shadowDy="4"
                            android:shadowRadius="2"
                            android:text="WEAPONS"
                            android:textColor="@color/colorWhite"
                            android:textSize="30sp" />

                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="0.3"
                    android:background="#000"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1">

                        <TextView
                            android:id="@+id/category_desc"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:paddingLeft="11dp"
                            android:text="Know your weapons before you shoot"
                            android:textColor="@color/colorLightWhite"
                            android:textScaleX="1" />
                    </LinearLayout>

                    <com.romainpiel.shimmer.ShimmerTextView
                        android:id="@+id/arrow_text"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="5dp"
                        android:layout_weight="0.2"
                        android:gravity="right"
                        android:text=">>>>>"
                        android:textColor="#000"
                        android:textScaleX="1.5"
                        android:textStyle="bold"
                        app:reflectionColor="#FFBF41" />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

    </android.support.v7.widget.CardView>
</FrameLayout>

你可以喜歡 Glide (4.7.1)

Glide.with(getActivity()).load(avatar)
                .apply(RequestOptions.bitmapTransform(new CircleCrop()).placeholder(R.mipmap.defaultusericon))
                .into(mUserIcon);

placeHolderOf僅當您在ImageView中加載它placeHolderOf設置 place Holder 圖像。 如果要將占位符設置為 ViewGroup, SimpleTarget類提供了一種方法,您可以在圖像開始加載時覆蓋該方法以設置背景。
在您的情況下嘗試加載如下:

Glide.with(mContext)
            .load("https://i.imgur.com/0k7ZFWr.png")
            .apply(RequestOptions.placeholderOf(R.drawable.pubgguide_icon))
            .into(new SimpleTarget<Drawable>() {

                @Override
                public void onLoadStarted(@Nullable Drawable resource) {
                    holder.cardImageLayout.setBackground(resource);
                }

                @Override
                public void onResourceReady(@NonNull Drawable resource, Transition<? super Drawable> transition) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        holder.cardImageLayout.setBackground(resource);
                        Drawable cardViewBackground = holder.cardImageLayout.getBackground();
                        cardViewBackground.setColorFilter(0x5F000000, PorterDuff.Mode.SRC_ATOP);
                    }
                }
            });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM