zoukankan      html  css  js  c++  java
  • 使用一个小图片tile平铺到ImageView中或Activity背景

    方法两种:

    首先必须在res/drawable目录下包含一个background.jpg

    方法1:在res/drawable中创建一个xml文件(background_repeat.xml)

                  内容为

     

    [html] view plaincopy
     
    1. <bitmap xmlns:android="http://schemas.android.com/apk/res/android"  
    2.     android:src="@drawable/background"  
    3.     android:tileMode="repeat"  
    4. />  



    然后再Activity的xml中

     

    [html] view plaincopy
     
    1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    2.     android:orientation="vertical"  
    3.     android:layout_width="fill_parent"  
    4.     android:layout_height="fill_parent"  
    5.     android:background="@drawable/background_repeat">  



    方法2:

     

    [java] view plaincopy
     
    1. imageView = (ImageView)findViewById(R.id.MainA_Iv);  
    2. Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.background);  
    3.   
    4. BitmapDrawable bd = new BitmapDrawable(bitmap);  
    5. bd.setTileModeXY(TileMode.REPEAT , TileMode.REPEAT );  
    [java] view plaincopy
     
      1. imageView.setBackgroundDrawable(bd);  
  • 相关阅读:
    hdu1421 搬寝室(dp)
    HDU 2577(DP)
    扩展欧几里德算法
    unique函数的作用
    区间更新 zoj3911
    set的应用
    vue 事件处理器
    vue Class与style绑定
    vue的计算属性
    sass入门
  • 原文地址:https://www.cnblogs.com/dongweiq/p/4721399.html
Copyright © 2011-2022 走看看