我希望将从互联网下载的图像设置为相对布局的背景,并具有透明属性。
以下是我在layout.xml文件中拥有的内容:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:id="@+id/mainLayout"
android:alpha="0.75" >
....
</RelativeLayout>
这是我从活动中尝试的内容:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeImageLoader();
String imageUri = "http://www.laederach.com/fileadmin/img/filialen/zermatt/zermattBg.jpg";
Bitmap bitmap = imageLoader.loadImageSync(imageUri1);
relativeLayout = (RelativeLayout)findViewById(R.id.mainLayout);
Drawable d =new BitmapDrawable(getResources(),bitmap);
relativeLayout.setBackground(new BitmapDrawable(bitmap));
}
private void initializeImageLoader() {
// Create global configuration and initialize ImageLoader with this configuration
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.build();
ImageLoader.getInstance().init(config);
}
但它并没有起作用。你知道为什么它不能运行或者我漏了什么吗?谢谢。