android设置背景平铺
2013-11-04 15:06
295 查看
以LinearLayout为例,它提供的background属性将会将背景图片拉伸,相当难看。事实上我们只需做少量的修改就可以实现web编程中css背景图片的效果。来试试吧。
Bitmap介绍
A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a BitmapDrawable from a file path, an input stream, through XML inflation, or from a Bitmap object.
[/size]
[size=large]属性android:tileMode
Defines the tile mode. When the tile mode is enabled, the bitmap is repeated. Gravity is ignored when the tile mode is enabled.
Constant Value Description
disabled -1 Do not tile the bitmap. This is the default value.
clamp 0 Replicates the edge color.
repeat 1 Repeats the bitmap in both direction.
mirror 2 Repeats the shader’s image horizontally and vertically, alternating mirror images so that adjacent images always seam.
创建重复的背景图片
在drawable目录下创建一个repeat_bg.xml:
<?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/bg" android:tileMode="repeat" />
然后在布局的xml文件中可以这样引用:
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/repeat_bg"> </LinearLayout>
来自http://www.haoni.org/2011/04/21/androidbeijingtupianzhongfubackgroundrepeat/
Bitmap介绍
A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a BitmapDrawable from a file path, an input stream, through XML inflation, or from a Bitmap object.
[/size]
[size=large]属性android:tileMode
Defines the tile mode. When the tile mode is enabled, the bitmap is repeated. Gravity is ignored when the tile mode is enabled.
Constant Value Description
disabled -1 Do not tile the bitmap. This is the default value.
clamp 0 Replicates the edge color.
repeat 1 Repeats the bitmap in both direction.
mirror 2 Repeats the shader’s image horizontally and vertically, alternating mirror images so that adjacent images always seam.
创建重复的背景图片
在drawable目录下创建一个repeat_bg.xml:
<?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/bg" android:tileMode="repeat" />
然后在布局的xml文件中可以这样引用:
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/repeat_bg"> </LinearLayout>
来自http://www.haoni.org/2011/04/21/androidbeijingtupianzhongfubackgroundrepeat/
相关文章推荐
- Android 调试桥
- android签名详解
- Android Apk包的签名出库、自动编译与混淆
- 鉴客 android程序启动画面之Splash总结
- Android Activity和Intent机制学习笔记
- 关于android.view.WindowLeaked(窗体泄露)的解决方案
- Android应用程序更新或升级
- Android中AsyncTask的用法实例
- android:inputType参数类型说明
- Android2.2中系统自带样式styles.x…
- Android&nbsp;Fragment的使用(1)&nbsp;[转]
- Android屏幕尺寸适配注意事项
- Android.mk高级写法
- Android(Java):minSdkVersion、targetSdkVersion、targetApiLevel的区别
- Android异常01----No package identifier when getting name for resource number 0x00000000 警告提示
- Android开发开源源代码
- android头像设置:从本地照片库或拍照获取并剪裁
- Android kernel wakelock分析
- Android基础知识总结系列(二)——Handler
- 终于搞定android驱动USB摄像头了!