android 项目中设置背景图片
2014-05-11 03:16
519 查看
xml文件设置背景图片中:任意一个控件,button imageView 或layout,在其的xml属性设置中,添加
[XML] view
plaincopy
android:background="@drawable/bg"
即可实现设置其背景图片为bg. 图片存放在drawable目录下。
drawable目录下存放大小图标共用的图片。drawable-hdpi中存放240 WVGA800 的模拟器或板子用的图片。drawable-mdpi存放对应的小图片
[XML] view
plaincopy
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pic"/>
同样,用src属性,也可设置imageView的图片为pic.png
java代码中设置或更改一个控件的背景图片:
[java] view
plaincopy
Resources resources = getContext().getResources();
Drawable btnDrawable = resources.getDrawable(R.drawable.layout_bg);
layout.setBackgroundDrawable(btnDrawable);
程序中,动态修改layout的背景图片,用setBackgroundDrawable()函数实现。设置其背景图片为 layout_bg.png 修改imageView1的背景图片为imageView2的背景图片:imageView2.getDrawable()可获得图片2的背景。值为Drawable类型imageView1.setImageDrawable(drawable);
设置imageView1的背景图片
[XML] view
plaincopy
android:background="@drawable/bg"
即可实现设置其背景图片为bg. 图片存放在drawable目录下。
drawable目录下存放大小图标共用的图片。drawable-hdpi中存放240 WVGA800 的模拟器或板子用的图片。drawable-mdpi存放对应的小图片
[XML] view
plaincopy
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pic"/>
同样,用src属性,也可设置imageView的图片为pic.png
java代码中设置或更改一个控件的背景图片:
[java] view
plaincopy
Resources resources = getContext().getResources();
Drawable btnDrawable = resources.getDrawable(R.drawable.layout_bg);
layout.setBackgroundDrawable(btnDrawable);
程序中,动态修改layout的背景图片,用setBackgroundDrawable()函数实现。设置其背景图片为 layout_bg.png 修改imageView1的背景图片为imageView2的背景图片:imageView2.getDrawable()可获得图片2的背景。值为Drawable类型imageView1.setImageDrawable(drawable);
设置imageView1的背景图片
相关文章推荐
- android 项目中设置背景图片
- android之设置app背景图片
- Android自定义Button并设置不同背景图片的方法
- Android布局自定义Shap圆形ImageView,可以单独设置背景与图片
- Android开发_如何设置按钮背景透明与半透明_图片背景透明
- Android设置背景图片平铺
- [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)
- Android开发_如何设置按钮背景透明与半透明_图片背景透明
- android 设置背景图片 xml的background和java的getDrawable()
- Android开发_如何设置按钮背景透明与半透明_图片背景透明
- android 设置背景图片
- android 读取sd卡(sdcard)图片设置为按钮背景(Button背景设置)代码
- AndroidMenu背景图片,背景色的设置
- android 设置背景图片 xml的background和java的getDrawable()
- Android设置背景图片平铺
- android设置背景图片透明
- android小问题:RadioButton设置文字在图片背景的下方
- Android开发_如何设置按钮背景透明与半透明_图片背景透明
- Vue项目中设置背景图片
- Android基础小技术点:Android ListView设置背景图片及分割线、周边距