For a linearLayout, I want to have a gradient along with a tiled (repeated) image in the background. I already have a shape xml set as the background
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:angle="90"
android:endColor="@color/color1"
android:startColor="@:color/color2">
</gradient>
</shape>
How do I add a tiled bg image?
Check out
LayerLists
.The following is an XML drawable, called
myBackground.xml
, placed inres/drawable
. Set it as the background of theView
you want to set a gradient and tiled background for.In the example below, the tiled image will be on top of the gradient, because it is specified later in the
LayerList
- obviously if it's on top, you'll need some transparency on the png image tile (you can set this in an image editing application, like GIMP or Photoshop)."tile_classy_fabric" refers to a file called "tile_classy_fabric.png" in my
res/drawable
folder (250px square, as it's tileable - we don't need it super large).