图像不会加载Glide

时间:2018-01-03 18:06:38

标签: android

当我使用 Glide 将图像加载到 ImageButtons 时,某些图像无法加载。我希望有人能解决我的问题。

这是我的代码:

.XML:

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="132dp"
            android:background="@android:color/transparent"
            android:scaleType="fitCenter"
            android:src="@drawable/csik_2"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageButton
            android:id="@+id/home_ib1_24_hours_to_live"
            android:layout_width="98dp"
            android:layout_height="155dp"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/imageView"
            android:layout_marginStart="16dp"
            android:layout_marginTop="32dp"
            android:background="@android:color/transparent"
            android:scaleType="fitCenter" />

        <ImageButton
            android:id="@+id/home_ib2_the_dancer"
            android:layout_width="98dp"
            android:layout_height="155dp"
            android:layout_alignTop="@+id/home_ib1_24_hours_to_live"
            android:layout_centerHorizontal="true"
            android:background="@android:color/transparent"
            android:scaleType="fitCenter" />

        <ImageButton
            android:id="@+id/home_ib3_shadowman"
            android:layout_width="98dp"
            android:layout_height="155dp"
            android:layout_alignParentEnd="true"
            android:layout_alignTop="@+id/home_ib2_the_dancer"
            android:layout_marginEnd="16dp"
            android:background="@android:color/transparent"
            android:scaleType="fitCenter" />

        <ImageButton
            android:id="@+id/home_ib4_keplers_dream"
            android:layout_width="98dp"
            android:layout_height="155dp"
            android:layout_alignStart="@+id/home_ib1_24_hours_to_live"
            android:layout_below="@+id/home_ib1_24_hours_to_live"
            android:layout_marginTop="14dp"
            android:background="@android:color/transparent"
            android:scaleType="fitCenter" />

        <ImageButton
            android:id="@+id/home_ib5_drawning_home"
            android:layout_width="98dp"
            android:layout_height="155dp"
            android:layout_alignTop="@+id/home_ib4_keplers_dream"
            android:layout_centerHorizontal="true"
            android:background="@android:color/transparent"
            android:scaleType="fitCenter" />

        <ImageButton
            android:id="@+id/home_ib6_another_wolfcop"
            android:layout_width="98dp"
            android:layout_height="155dp"
            android:layout_alignStart="@+id/home_ib3_shadowman"
            android:layout_alignTop="@+id/home_ib5_drawning_home"
            android:background="@android:color/transparent"
            android:scaleType="fitCenter" />

        <ImageButton
            android:id="@+id/home_ib7_monster_truck"
            android:layout_width="98dp"
            android:layout_height="155dp"
            android:layout_alignStart="@+id/home_ib4_keplers_dream"
            android:layout_below="@+id/home_ib4_keplers_dream"
            android:layout_marginTop="14dp"
            android:background="@android:color/transparent"
            android:scaleType="fitCenter" />

        <ImageButton
            android:id="@+id/home_ib8_underworld_blood_wars"
            android:layout_width="98dp"
            android:layout_height="155dp"
            android:layout_alignParentBottom="true"
            android:layout_alignStart="@+id/home_ib5_drawning_home"
            android:background="@android:color/transparent"
            android:scaleType="fitCenter" />

        <ImageButton
            android:id="@+id/home_ib9_the_disaster_artist"
            android:layout_width="98dp"
            android:layout_height="155dp"
            android:layout_alignParentBottom="true"
            android:layout_alignStart="@+id/home_ib6_another_wolfcop"
            android:background="@android:color/transparent"
            android:scaleType="fitCenter" />


    </RelativeLayout>
</ScrollView>

(整个.xml位于 ScrollView 之外的 RelativeLayout

的.java:

ImageButton home_ib1_24_hours_to_live;
ImageButton home_ib2_the_dancer;
ImageButton home_ib3_shadowman;
ImageButton home_ib4_keplers_dream;
ImageButton home_ib5_drawning_home;
ImageButton home_ib6_another_wolfcop;
ImageButton home_ib7_monster_truck;
ImageButton home_ib8_underworld_blood_wars;
ImageButton home_ib9_the_disaster_artist;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_home);

    home_ib1_24_hours_to_live = (ImageButton)findViewById(R.id.home_ib1_24_hours_to_live);
    Glide.with(Home.this)
            .load(R.drawable.moviep_24_hours_to_live)
            .centerCrop()
            .fitCenter()
            .into(home_ib1_24_hours_to_live);

    home_ib2_the_dancer = (ImageButton)findViewById(R.id.home_ib2_the_dancer);
    Glide.with(Home.this)
            .load(R.drawable.moviep_the_dancer)
            .centerCrop()
            .fitCenter()
            .into(home_ib2_the_dancer);

    home_ib3_shadowman = (ImageButton)findViewById(R.id.home_ib3_shadowman);
    Glide.with(Home.this)
            .load(R.drawable.moviep_shadowman)
            .centerCrop()
            .fitCenter()
            .into(home_ib3_shadowman);

    home_ib4_keplers_dream = (ImageButton)findViewById(R.id.home_ib4_keplers_dream);
    Glide.with(Home.this)
            .load(R.drawable.moviep_kerlers_dream)
            .centerCrop()
            .fitCenter()
            .into(home_ib4_keplers_dream);

    home_ib5_drawning_home = (ImageButton)findViewById(R.id.home_ib5_drawning_home);
    Glide.with(Home.this)
            .load(R.drawable.moviep_drawing_home)
            .centerCrop()
            .fitCenter()
            .into(home_ib5_drawning_home);

    home_ib6_another_wolfcop = (ImageButton)findViewById(R.id.home_ib6_another_wolfcop);
    Glide.with(Home.this)
            .load(R.drawable.moviep_another_wolfcop)
            .centerCrop()
            .fitCenter()
            .into(home_ib6_another_wolfcop);

    home_ib7_monster_truck = (ImageButton)findViewById(R.id.home_ib7_monster_truck);
    Glide.with(Home.this)
            .load(R.drawable.moviep_monster_truck)
            .centerCrop()
            .fitCenter()
            .into(home_ib7_monster_truck);

    home_ib8_underworld_blood_wars = (ImageButton)findViewById(R.id.home_ib8_underworld_blood_wars);
    Glide.with(Home.this)
            .load(R.drawable.moviep_underworld_blood_wars)
            .centerCrop()
            .fitCenter()
            .into(home_ib8_underworld_blood_wars);

    home_ib9_the_disaster_artist = (ImageButton)findViewById(R.id.home_ib9_the_disaster_artist);
    Glide.with(Home.this)
            .load(R.drawable.moviep_the_disaster_artist)
            .centerCrop()
            .fitCenter()
            .into(home_ib9_the_disaster_artist);

你可以看到我的所有代码,然后查看问题的图片。当我重新启动应用程序时,它工作了,当我重新启动时,它不起作用,但是另一张图片没有&#39;加载(所以我们可以说它&#34;工作&#34;随机)。 我将这一行添加到我的 Build.Gradle / app:compile&#39; com.github.bumptech.glide:glide:3.8.0&#39; (并且LogCat没有&#34;说&#34;出现问题)

这里是图片: In the red line would be an antoher image like the others

在红线中将是与其他人一样的另类图像。

提前感谢您的帮助。 (我的平均回复时间是30分钟)

编辑: 如果跳过任何内存缓存,我怎么能不跳过缓存?

1 个答案:

答案 0 :(得分:0)

看起来代码没有问题,你的最低API级别是什么?

跟踪您的日志以查看是否有缓存跳过。如果不能尝试这个:

 @Override
    protected void onDetachedFromWindow () {
        Glide.clear(this);
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            setBackgroundDrawable(null);
        } else {
            setBackground(null);
        }
        setImageBitmap(null);
        System.gc();
    }