Forked from codeswimmer/Android: Tiled Background
Last active
August 29, 2015 14:11
-
-
Save beshkenadze/1d04b717c71b2a1554d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============================================================================================ | |
// Code | |
// | |
// Example showing how to set a View's background to a tiled bitmap. | |
// assumes: res/drawable/pattern01.png - The bitmap representing an individual tile | |
public void setViewTiledBackground(View view, Resources resources) { | |
Bitmap tile = BitmapFactory.decodeResource(resources, R.drawable.pattern02); | |
BitmapDrawable tiledBitmapDrawable = new BitmapDrawable(resources, tile); | |
tiledBitmapDrawable.setTileModeX(Shader.TileMode.REPEAT); | |
tiledBitmapDrawable.setTileModeY(Shader.TileMode.REPEAT); | |
view.setBackgroundDrawable(tiledBitmapDrawable); | |
} | |
// ============================================================================================ | |
// XML | |
// | |
// Example shows how to display a tiled image as a ViewGroup's background. | |
assumes: res/drawable/pattern01.png - The bitmap representing an individual tile | |
/* res/layout/main.xml ************************************************************************ | |
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" android:layout_width="fill_parent" | |
android:layout_height="fill_parent" android:background="@drawable/tiled"> | |
</LinearLayout> | |
***********************************************************************************************/ | |
/* res/layout/drawable/tiled.xml ************************************************************** | |
<?xml version="1.0" encoding="utf-8"?> | |
<bitmap | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:src="@drawable/pattern01" | |
android:dither="true" | |
android:tileMode="repeat" | |
android:dither="true" | |
/> | |
***********************************************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment