Tiling images in android with ImageView in XML

前端 未结 1 1767
轻奢々
轻奢々 2021-01-04 23:34

I am trying to get an image on the background to tile until the background is full.

My current code is:



        
相关标签:
1条回答
  • 2021-01-05 00:14

    First, place your image in a file like res/drawable/cloud.png. This makes it accessible to your app as @drawable/cloud. But it doesn't tile (yet).

    Next, you should define a bitmap resource(1) with android:tileMode="repeat". For example, you can define it on mytileablebitmap.xml:

    <bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:tileMode="repeat" 
    android:src="@drawable/cloud"/>
    

    This is referencing your original tile image (drawable/cloud) and making a Drawable that knows how to tile itself to fill the available space.

    Then, when you want to use the tiled background, use "@drawable/mytileablebitmap".

    (1): http://developer.android.com/guide/topics/resources/drawable-resource.html

    0 讨论(0)
提交回复
热议问题