【发布时间】:2015-07-17 18:09:07
【问题描述】:
我有一个线性布局,我想以编程方式更改其背景:
<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" >
...
我尝试使用以下方法设置 XML 布局的背景图像:
LinearLayout linearLayout2 = (LinearLayout) findViewById(R.id.downloadLayout);
int resId = getResources().getIdentifier(background,
"drawable", getPackageName());
linearLayout2.setBackgroundResource(resId);
但是背景图像永远不会加载,没有 NPE,图像根本就永远不会加载。任何建议表示赞赏。
我做了一些调试,我目前有以下值:
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
附言
我也尝试过使用 Picasso 完成相同的操作 - 我不确定如何解决所述错误并成功加载:
来源:
final LinearLayout downloadLayout = (LinearLayout) findViewById(R.id.downloadLayout);
Picasso.with(this).load("http://i.imgur.com/DvpvklR.png").into(downloadLayout);
错误:
The method into(Target) in the type RequestCreator is not applicable for the arguments (LinearLayout)
【问题讨论】:
标签: android android-layout background android-linearlayout