public void paint() {
if (item.laying_mode != 1)//平铺或者充满
{
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
Looper.prepare();
try {
theBitmap = Glide.
with(ctxt).
load(item.src).
asBitmap().
into(fenbianlv[0], fenbianlv[1]).
get();
} catch (final ExecutionException e) {
Log.e(TAG, e.getMessage());
} catch (final InterruptedException e) {
Log.e(TAG, e.getMessage());
}
return null;
} @Override
protected void onPostExecute(Void dummy) {
if (null != theBitmap) {
// The full bitmap should be available here BitmapDrawable bd = new BitmapDrawable(Resources.getSystem(),theBitmap);
if (item.laying_mode == 0)//充满(默认值,缩放到图片全部充满屏幕
{
} else if (item.laying_mode == 2)//平铺(从左上开始,一个一个的平铺)
{
bd.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
}
rl.setBackground(bd);
}
}
}.execute();
}
else//1:居中(图片按照原始大小,放到屏幕中间)
{
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
Looper.prepare();
try {
String imageUrl = item.src;
theBitmap= BitmapFactory.decodeStream((InputStream) new URL(imageUrl).getContent());
} catch (final Exception e) {
Log.e(TAG, e.getMessage());
}
return null;
} @Override
protected void onPostExecute(Void dummy) {
if (null != theBitmap) {
iv.setImageBitmap(theBitmap);
}
}
}.execute();
}
}
一下三种分别是充满、平铺、居中(按图片原始大小)