繁体   English   中英

图片无法使用Glide加载

[英]Images doesn't loading with Glide

当我使用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);

您可以看到我的所有代码,并在问题的图片下方。.当我重新启动应用程序时,它可以正常工作,而当我再次重新启动时,它不起作用,但是没有加载其他图片(所以我们可以说它“随机”运行)。 并将此行添加到Build.Gradle / app中:编译'com.github.bumptech.glide:glide:3.8.0'(LogCat不会“说”出任何问题)

这是图片: 红线中将是其他图像

红线中将是其他图像。

我在这里先向您的帮助表示感谢。 (我的平均回复时间是30分钟)

编辑:如果跳过任何内存缓存,如何不跳过缓存?

看起来代码没有什么问题,您的最低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();
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM