使用Picasso动态加载ImageButton图像

时间:2015-12-30 21:07:26

标签: android picasso android-imagebutton

我正在尝试将多个图像按钮加载到ScrollView中。这是我正在使用的代码,

Picasso.with(getContext()).load(url).into(new Target() {
    @Override
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
        BitmapDrawable bdrawable = new BitmapDrawable(bitmap);
        btn.setBackground(bdrawable);
    }

    @Override
    public void onBitmapFailed(Drawable errorDrawable) {

    }

    @Override
    public void onPrepareLoad(Drawable placeHolderDrawable) {

    }
});
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
params.topMargin = 0;
btn.setLayoutParams(params);
btn.setAdjustViewBounds(true);
btn.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
scrollLayout.addView(btn);

但图像未按预期加载。怎么回事?

感谢。

0 个答案:

没有答案