温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么用Glide框架缓存压缩图片做一个网络图片查看器

发布时间:2021-10-29 15:40:07 来源:亿速云 阅读:227 作者:iii 栏目:编程语言

这篇文章主要介绍“怎么用Glide框架缓存压缩图片做一个网络图片查看器”,在日常操作中,相信很多人在怎么用Glide框架缓存压缩图片做一个网络图片查看器问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用Glide框架缓存压缩图片做一个网络图片查看器”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

ImgActivity.java

package com.example.a20200712;
 
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
 
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
 
import com.bumptech.glide.Glide;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
 
public class ImgActivity extends AppCompatActivity {
 
    private EditText imgPath;
    private ImageView img;
 
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.img_view_layout);
        imgPath = findViewById(R.id.img_layout_imgText);
        img = findViewById(R.id.img_layout_img);
    }
 
    public void imgviewonClick(View view) {
        Glide.with(ImgActivity.this).load(imgPath.getText().toString()).into(img);
    }

}

img_view_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/img_layout_imgText"
        android:hint="请输入地址">
 
    </EditText>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="查看"
        android:onClick="imgviewonClick"></Button>
    <ImageView
        android:id="@+id/img_layout_img"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ImageView>
</LinearLayout>

到此,关于“怎么用Glide框架缓存压缩图片做一个网络图片查看器”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI