can you put an image in a gradient as background in android?

0

Good, as the question says, I would like to know if in a degraded background you can put a small image either in the center or in any place of the design, and all this put it as background of an activity.

That I know the gradients are created in the "Drawable" directory and with the label:

 < shape> < /shape>

but, in addition to this, I wanted to know if this background can be added an image that is part of the whole background as I do not know if there is a label that allows that or I have to create another file and join both resources (one of the gradient and one of the image).

I hope some help hehe Thanks in advance.

    
asked by Dan Ber 10.01.2018 в 06:43
source

2 answers

1

Yes you can, use the following:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle" android:padding="5dp">
            <corners
                 android:bottomRightRadius="5dp"
                 android:bottomLeftRadius="5dp"
                 android:topLeftRadius="5dp"
                 android:topRightRadius="5dp"/>
         </shape>
   </item>
   <item android:drawable="@drawable/nombre_de_tu_imagen />

</layer-list>
    
answered by 10.01.2018 / 09:38
source
0

Create a gradient inside the folder \drawable for example gradiente.xml, where you mainly define the initial and final color, in this example you define a green color as initial:

   android:startColor="00FF00"

and a black color as the end:

   android:endColor="#000000"

file gradiente.xml :

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="00FF00"
        android:endColor="#000000"
        android:angle="270" />
</shape>

This gradient is assigned as background in the layout and as foreground the image:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:foreground="@drawable/androide"
    android:background="@drawable/gradiente">
</LinearLayout>

to obtain the image as a result and as a background the gradient:

    
answered by 10.01.2018 в 16:50