以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.
属性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/
<xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/MainLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/backrepeat"
>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/tile"
android:tileMode="repeat"
android:dither="true" /><!-- dither="true"震动-->
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.
属性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/
<xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/MainLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/backrepeat"
>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/tile"
android:tileMode="repeat"
android:dither="true" /><!-- dither="true"震动-->
发表评论
-
android:gravity / android:layout_Gravity,android:padding / android:layout_margin
2012-04-07 15:21 1072android:gravity / android:layou ... -
Android触控屏幕Gesture(GestureDetector和SimpleOnGestureListener的使用教程)
2011-11-18 16:51 8201、当用户触摸屏幕的时候,会产生许多手势,例如down,up, ... -
Android ImageView 总结
2011-11-17 17:17 1203一.介绍 ImageView用来显示任意图像图片,可以自己定义 ... -
简述Android触摸屏手势识别
2011-11-16 16:45 927很多时候,利用触摸屏的Fling、Scroll等Gesture ... -
简述Android触摸屏手势识别
2011-11-16 15:49 920在Android系统中,手势的识别是通过 GestureDet ... -
Android TextView属性详解
2011-11-10 17:12 755android:autoLink设置是否当 ... -
android监听返回按钮事件
2011-11-08 18:38 738用户在点击手机的返回按钮时,默认是推出当前的activty,但 ... -
android 完全退出程序
2011-11-08 18:37 731有几个activity,有一需 ... -
Android onTouchEvent, onClick及onLongClick的调用机制
2011-11-07 15:31 903针对屏幕上的一个View控 ... -
Android WebView放大缩小缩放
2011-11-02 10:27 2533一般情况下通过设置一下参数缩放 wv.getSettings ... -
Android控件之ZoomControls缩放控件
2011-11-01 17:14 1083一、简介 ZoomControls是一组可缩放的控件。它 ... -
Android通过手势实现的缩放处理
2011-11-01 17:12 1033主要原理是onTouchEvent事件中的参数MotionEv ... -
TextView 加下划线
2011-10-30 14:10 970如果是在资源文件里,可以这样写. Xml代码 ... -
Android TextView(EditView)文字底部或者中间加横线
2011-10-30 14:08 1636promotionLinkText = (TextView) ... -
TextView中显示HTML和图片
2011-10-30 13:55 1067在TextView中显示<img src="& ... -
android 3d 旋转
2011-10-27 16:23 1148在javaeye里看到了关于3d旋转的文章 效果图: 这 ... -
android 之 GridView
2011-10-27 14:14 764GridView 的用法基本与ListView类似。 ... -
android GridView的使用
2011-10-27 14:12 1407GridView跟ListView都是比较常用的多控件布局,而 ... -
android之ImageView
2011-10-26 22:17 969ImageView 首先确定下ImageView的全路径: ... -
布局学习—活用RelativeLayout
2011-10-26 00:40 656前言 Android布局中RelativeLayout非 ...
相关推荐
主要介绍了css3实现一个div设置多张背景图片及background-image属性,同时对于css3背景渐变也做了详细的解释,水平渐变,左上角渐变等等方式,需要的朋友可以参考下
在做下拉框select的时候用一个箭头符号,作为下拉框的三角,在firefox和chrome下均可以正常显示,但是在IE下无法显示。 查找了很久,发现是图片格式问题,把png格式的... background:url(images/arrow.gif) no-repeat 1
android-ripple-background.zip,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
CSS中背景图片定位方法:background-position的用法,附带算法
(我把整个项目的配置文件都打包了,看着有点大,其实app大小只有2.3M)Android 中使用webp,一行代码使用,缩小app体积,Android中图片优化之WebP使用
App设置android隐藏的RUN_IN_BACKGROUND权限,需要root
简化View的background创建,支持在xml和代码中设置backgroundDrawable
background-repeat 的学习.zip下载!
下面代码实现div层背景图片在底部显示: 复制代码代码如下: div { background:url(/images/bg.jpg) no-repeat ... /*背景图片不重复显示*/ background-repeat:repeat; /*背景图片横向及纵向重复*/ background-repea
android沉浸状态栏和顶部状态栏背景色的设置,现在很多应用都引用了沉浸式状态栏这样的效果,这样的效果很酷炫。
在css中,可以利用“background-size”属性设置背景图片自适应大小,该属性用于设置背景图片的大小,只需要给背景图片元素添加“background-size:cover;”样式,即可使背景图片的大小自适应。
1> 准备背景图片: background_pix.png 注:用背景图片比用颜色好处,可以让背景看起来有凹凸感. 2> drawable文件夹下放xml文件 bitmap_repeat.xml <?xml version=1.0 encoding=utf-8?> <bitmap xmlns:android=...
cordova-background-geolocation-services, Android和iOS的背景定位 cordova-background-geolocation-servicesAndroid和iOS的background 地理定位,纯javascript回调。注意:如果有人有兴趣,这个插件需要一个维护...
那么这篇文章将详细介绍了这几种背景图片的处理方法。 正如前面所说,仅仅依靠CSS现有的属性,我们无法实现背景裁切、背景透明度、背景变换和复杂背景定位等效果.为了实现这些效果,我们需要借助CSS的其他方法来实现...
src是图片内容(前景),bg是背景,可以同时使用。 此外:scaleType只对src起作用;bg可设置透明度,比如在ImageButton中就可以用android:scaleType控制图片的缩放方式,示例代码如下: <ImageView android:id=...
对大多数Android的开发者来说,最经常的操作莫过于对界面进行布局,View中背景图片的加载是最经常做的。但是我们很少关注这个过程,这篇文章主要解析view中背景图片加载的流程。了解view中背景图片的加载(资源的...
所以实际的结果是只能重复显示,所以出现了repeat,repeat-x,repeat-y,no-repeat这些属性。就是用来控制背景图片的显示的。所以一般用作背景图片的有2类: 1.是一整张大图,尺寸和区域大小刚好吻合 2.一个很小的...
Android中带圆角以及不同背景颜色的TextView,如果使用xml实现的话针对不同的颜色需要写一个xml文件,这样太繁琐了,所以就自己写了一个控件,只要设置一下属性就可以达到想要的目的
•background-color 颜色 •background-position 位置 •background-size 大小 •background-repeat 如何重复背景图像 •background-origin 背景图片的定位区域 •background-clip 背景的绘制区域 •background-...
小程序background引入图片展示不完整 文章链接:https://blog.csdn.net/qq_36413371/article/details/100543936