【问题标题】:How to set the imageview as the background image of my LinearLayout from Picasso image loader programmatically?如何以编程方式从 Picasso 图像加载器将图像视图设置为我的 LinearLayout 的背景图像?
【发布时间】:2015-12-14 16:01:26
【问题描述】:

我正在使用Picasso 类/库从url 加载图像并将图像显示到ImageView。我是否可以通过 picasso 图像加载器从url 加载的imageview 以编程方式设置为linearlayout 的背景图像?

【问题讨论】:

    标签: android image android-layout android-imageview picasso


    【解决方案1】:

    我已经发现了这个问题 - 可能对你有用:

    How do i set background image with picasso in code

    据此,使用毕加索的回调

    Picasso.with(getActivity()).load(R.drawable.table_background).into(new Target(){
    
        @Override
        public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
           mainLayout.setBackground(new BitmapDrawable(context.getResources(), bitmap));
        }
    
        @Override
        public void onBitmapFailed(final Drawable errorDrawable) {
            Log.d("TAG", "FAILED");
        }
    
        @Override
        public void onPrepareLoad(final Drawable placeHolderDrawable) {
            Log.d("TAG", "Prepare Load");
        }      
    })
    

    另请阅读

    Set background resource using Picasso

    但你会找到相同的解决方案。

    【讨论】:

    • 可悲的是“新的 BitmapDrawable”已被弃用
    猜你喜欢
    • 1970-01-01
    • 2013-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多