无法使用URL毕加索设置的LinearLayout BackgroundResource [英] Unable to set LinearLayout BackgroundResource from URL using Picasso

查看:149
本文介绍了无法使用URL毕加索设置的LinearLayout BackgroundResource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的LinearLayout我想改变的编程背景:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / downloadLayout
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT    机器人:weightSum =1>
    ...

和我已经尝试使用设置XML布局的背景图像以下内容:

 的LinearLayout linearLayout2 =(的LinearLayout)findViewById(R.id.downloadLayout);
        INT渣油= getResources()。则getIdentifier(背景下,
                可拉伸,getPackageName());

linearLayout2.setBackgroundResource(渣油);

然而背景图像从未载荷,没有NPE,图像根本从未载荷。任何建议都AP preciated。

我已经做了一些调试和我目前有以下值:

  linearLayout2 = {android.widget.LinearLayout 529b3f58 V.E ..... ......我。 0,0-0,0#7f0a008e应用:ID / downloadLayout}
        背景= http://xxx.xxx.x.xxx/bgs/big_lebowski_bg.jpg
        渣油= 0

P.S。

我也试过办成使用相同的毕加索 - 我不知道如何绕过所述的错误,并成功地加载:

来源:

 最后的LinearLayout downloadLayout =(的LinearLayout)findViewById(R.id.downloadLayout);
Picasso.with(本).load(http://i.imgur.com/DvpvklR.png).into(downloadLayout);

错误:

 在类型RequestCreator的方法为(目标)不适用于参数(的LinearLayout)


解决方案

毕加索的作品与ImageViews而已,没有布局。

您可以把一个ImageView的布局里面,将其设置为满足父母的宽度和高度,并注入图像到ImageView的。

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:ID =@ + ID / downloadLayout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:weightSum =1>
        < ImageView的
            机器人:ID =@ + ID / ImageView的
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent/>
< / LinearLayout中>

这应该工作,则:

  ImageView的ImageView的=(ImageView的)findViewById(R.id.imageView);
Picasso.with(本).load(http://i.imgur.com/DvpvklR.png).into(ImageView的);

I have a linearLayout I'd like to change the background of programatically:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/downloadLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:weightSum="1" >
    ...

and I've attempted to set the background Image of the XML layout using the following:

LinearLayout linearLayout2 = (LinearLayout) findViewById(R.id.downloadLayout);
        int resId = getResources().getIdentifier(background,
                "drawable", getPackageName());

linearLayout2.setBackgroundResource(resId);

However the background image never loads, there is no NPE, the image simply never loads. Any suggestions are appreciated.

I've done a bit of debugging and I currently have the following values:

        linearLayout2 = android.widget.LinearLayout{529b3f58 V.E..... ......I. 0,0-0,0 #7f0a008e app:id/downloadLayout}
        background = http://xxx.xxx.x.xxx/bgs/big_lebowski_bg.jpg
        resID = 0

P.S.

I've also tried accomplishing the same using Picasso - I'm not sure how to get around the error stated and load it successfully:

Source:

final LinearLayout downloadLayout = (LinearLayout) findViewById(R.id.downloadLayout);
Picasso.with(this).load("http://i.imgur.com/DvpvklR.png").into(downloadLayout);

Error:

The method into(Target) in the type RequestCreator is not applicable for the arguments (LinearLayout)

解决方案

Picasso works with ImageViews only, not layouts.

You could put an ImageView inside your layout, set it to match parent's width and height, and inject the image into the ImageView.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/downloadLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="1" >
        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
</LinearLayout>

This should work then:

ImageView imageView = (ImageView) findViewById(R.id.imageView);    
Picasso.with(this).load("http://i.imgur.com/DvpvklR.png").into(imageView);

这篇关于无法使用URL毕加索设置的LinearLayout BackgroundResource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆