阳光网驿-企业信息化交流平台【DTC零售连锁全渠道解决方案】

 找回密码
 注册

QQ登录

只需一步,快速开始

扫描二维码登录本站

手机号码,快捷登录

老司机
查看: 1181|回复: 0

[转帖] Android 背景图片重复 Background repeat

[复制链接]
  • TA的每日心情
    开心
    2012-3-7 10:15
  • 签到天数: 11 天

    [LV.3]偶尔看看II

    发表于 2012-1-3 11:13:50 | 显示全部楼层 |阅读模式
    以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:
    1<?xml version="1.0" encoding="utf-8"?>

    2<bitmap xmlns:android="http://schemas.android.com/apk/res/android"

    3    android:src="@drawable/bg" ;

    4    android:tileMode="repeat" />




    然后在布局的xml文件中可以这样引用:
    1<LinearLayout android:layout_width="fill_parent"

    2    android:layout_height="fill_parent"

    3    android:background="@drawable/repeat_bg">

    4;</LinearLayout>



    创建横向重复的背景图repeat-x
    创建纵向重复的背景图repeat-y


    楼主热帖
    启用邀请码注册,提高发帖质量,建设交流社区
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    快速回复 返回顶部 返回列表