【发布时间】:2016-05-05 01:59:13
【问题描述】:
我有一个带有 imageview 和 textview 的 recyclerview,我想使用质量差的下载来填充以加速下载过程。
imageview 有一个 onclick 方法,它显示一个对话框,其中下载的图像像背景一样,所以,我想下载质量差的图像,只有当用户点击图像时,然后下载高质量的图像。
这是我的下载代码:
try {
ruta = "http://192.168.1.67/apptequila/fotos/" + usuariojSON + "/" + fotojSON;
URL url = new URL(ruta);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(15000);
connection.connect();
InputStream input = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(input);
}catch (SocketTimeoutException e){
cancelarHilo(3);
} catch (Exception e) {
Log.i("SMS", "ERROR AL OBTENER FOTO: " + e.toString());
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.sin_perfil);
}
data.add(new MiModel(nombrejSON, categoriajSON, likesjSON, lemajSON, bitmap, idsjSON,latitudjSON,longitudjSON,distanciajSON));
onclick imageview的代码:
public void Pressimage(final int position) {
customDiag = new Dialog(MainActivity.this);
customDiag.requestWindowFeature(Window.FEATURE_NO_TITLE);
customDiag.setContentView(R.layout.dialog);
RelativeLayout relativeLayout = (RelativeLayout)customDiag.findViewById(R.id.root);
Drawable drawable = new BitmapDrawable(getApplicationContext().getResources(),
data.get(position).getImagen());
if(Build.VERSION.SDK_INT > 16) {
relativeLayout.setBackground(drawable);
}else{
relativeLayout.setBackgroundDrawable(drawable);
}
customDiag.show();
}
【问题讨论】:
标签: android image bitmap download httpconnection