How can I merge a background image with a color in an ANDROID layout?

0

I have an xml file where from another xml I call him and he paints two squares where I fill in a text. This box has a background color, but my idea is to also add a background image and merge with that color.

XML:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/fondo1Positivo" />
<stroke
    android:width="3dip"
    android:color="#282828" />
<corners android:radius="10dip" />
<padding
    android:left="0dip"
    android:top="0dip"
    android:right="0dip"
    android:bottom="0dip" />
</shape>

My idea is to do something similar to this: In this:

    
asked by Eduardo 04.05.2017 в 13:00
source

1 answer

1

The color definition you can use the system ARGB (Alpha Red Green Blue) with the alpha channel you can set the opacity of the color.

FF => 100% and 00 => 0%

the equivalence of not establishing alpha channel is as if it is 100%

282828 == FF282828

If you want to give it a little transparency try with 88......

In your particular case, you want the text to pick up a bit of color depending on the back, because the color of the text if you define a small transparency will let that color% of the background pass.

Merge two images of the same size

You can create a resource in drawable fusion.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/img_background" />
    <item android:drawable="@drawable/img_overlay" />
</layer-list>

and use as a resulting image @drawable/fusión

Another way It is to use a layout FrameLayout or RelativeLayout that you can even position the image overlapped where you want.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/img_blend"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageView
    android:id="@+id/image1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/background" />

    <ImageView
    android:id="@+id/image2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/watermark"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

</RelativeLayout>

The images you can define if you want to be able to center, crop etc ... here the documentation from google

    
answered by 04.05.2017 в 14:08