Android background背景图片平铺

说明:

有一个小图片,然后实现图片背景平铺,这样会就会像html的css一样方便使用了。

方法一:

首先:在res/drawable中创建一个xml文件(background_repeat.xml)



然后布局中调用:

方法二:

代码:

    imageView = (ImageView)findViewById(R.id.MainA_Iv);  
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.background);  
      
    BitmapDrawable bd = new BitmapDrawable(bitmap);  
    bd.setTileModeXY(TileMode.REPEAT , TileMode.REPEAT );  

设置:

imageView.setBackgroundDrawable(bd);  

效果图:


你可能感兴趣的:(【,Android,基础开发,】)