Gradient stroke with transparent background
Asked Answered
K

1

12

Im trying to achieve something like this, I used layer list in the xml this way :

<item>
    <shape android:shape="rectangle" >
        <gradient

            android:centerColor="#4DD0E1"
            android:endColor="#76FF03"

            android:startColor="@color/colorPrimary"
            android:type="linear" />


    </shape>
</item>

<item
    android:bottom="2dp"
    android:left="2dp"
    android:right="2dp"
    android:top="2dp">


    <shape android:shape="rectangle" >

        <solid android:color="#fff" />
    </shape>
</item>

Here is the layout code, the border of the shape needs to overlap the image.

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_marginTop="12dp"
        android:background="@android:color/transparent">


        <ImageView
            android:layout_width="100dp"
            android:layout_height="75dp"
            android:layout_centerVertical="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginRight="12dp"
            android:id="@+id/goals_image" />


        <FrameLayout
            android:id="@+id/goals_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            android:layout_gravity="center"
            android:clickable="true"

            android:layout_marginLeft="20dp"
            android:layout_marginRight="32dp"
            android:background="#00000000"
            >


            <TextView
                android:id="@+id/goals_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="15dp"
                android:text="Lose Weight"
                android:textColor="@color/black"
                android:layout_margin="40dp"

                />


        </FrameLayout>

    </RelativeLayout>

but if I set the background to transparent the shapes background becomes the whole gradient color. How can i achieve a gradient stroke with a transparent background? Thanks in advance.

enter image description here

Kortneykoruna answered 18/12, 2017 at 8:18 Comment(5)
share your layoutAspirate
@Maddy I edited the question with the layout codeKortneykoruna
@AhmadSabeh I am at exactly the same point now. Unfortunately none of the answers do the job.. any suggestions on how you solved it?Denham
just use code, YourView extends RelativeLayoutMozza
it is possible ?Villa
B
-3

Just use an 8-digit color value, e.g. #FFF8F8F6, where the first two characters are the alpha value. FF being fully opaque, and 00 being fully transparent.

Check this

How to make transparent gradient?

Check this also http://www.coderzheaven.com/2013/02/04/create-transparency-image-android/

Bioecology answered 18/12, 2017 at 9:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.