Desenhe forma personalizada drawable no android

votos
2

Eu quero desenhar uma forma personalizada no xmlesquema como abaixo:

digite

Eu tentei fazer algum código em XML, mas eu não entendo como dar efeito de sombra para delinear desta sombra.

O que eu fiz :

<?xml version=1.0 encoding=utf-8?>
<layer-list xmlns:android=http://schemas.android.com/apk/res/android>

    <item
        android:width=20dp
        android:height=20dp
        android:gravity=top|left>
        <rotate
            android:fromDegrees=45
            android:pivotX=50%
            android:pivotY=50%
            android:toDegrees=45>
            <shape android:shape=rectangle>

                <corners android:bottomRightRadius=2dp/>

                <gradient android:type=linear android:angle=270 android:startColor=#ffffff android:endColor=#ffffff/>
            </shape>

        </rotate>
    </item>
    <item
        android:width=120dp
        android:height=36dp
        android:bottom=6dp>
        <shape android:shape=rectangle>

            <gradient
                android:angle=0
                android:endColor=@color/color_white
                android:startColor=@color/color_white
                android:type=linear />

            <corners android:radius=6dp />

        </shape>

    </item>
</layer-list>

O que eu tenho no resultado:

digite

Alguém pode sugerir-me como eu posso dar sombra para delinear como no acima mencionado quadro? Ou qualquer outra solução semelhante imagem 9 remendo. Como posso desenhar tal imagem 9 patch?

Publicado 20/09/2018 em 04:28
fonte usuário
Em outras línguas...                            


4 respostas

votos
1

Mesmo melhor maneira Não crie forma inteira usando layer-list

  • A principal desvantagem com isso é que você precisa para dar fixo highte widthdeshape

Use Maneira simples basta criar seta superior usando layer-liste de usar como abaixo da amostra

tente este

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:orientation="vertical">

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginStart="10dp"
        android:src="@drawable/test" />


    <LinearLayout
        android:id="@+id/rootView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:orientation="vertical">


        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text=" Lorem ipsum dolor sit amet, consectetur adipiscing elit"
            android:textColor="@color/colorAccent" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text=" Lorem ipsum dolor sit amet, consectetur adipiscing elit"
            android:textColor="@android:color/black" />


    </LinearLayout>


</LinearLayout>

@ Drawable / test"

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <rotate
            android:fromDegrees="45"
            android:pivotX="-40%"
            android:pivotY="87%"
            android:toDegrees="45">
            <shape android:shape="rectangle">
                <stroke
                    android:width="10dp"
                    android:color="@android:color/white" />
                <solid android:color="@android:color/white" />
            </shape>
        </rotate>
    </item>
</layer-list>

SAÍDA

digite descrição da imagem aqui

Respondeu 20/09/2018 em 04:30
fonte usuário

votos
0

tente este

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:width="121dp"
    android:height="37dp"
    android:bottom="5dp">
    <shape android:shape="rectangle">

        <stroke
            android:color="@color/lightgrey"
            android:width="1dp"/>

    </shape>

</item>
<item
    android:width="21dp"
    android:height="21dp"
    android:gravity="top|left">
    <rotate
        android:fromDegrees="45"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="45">
        <shape android:shape="rectangle">
            <stroke
                android:color="@color/lightgrey"
                android:width="1dp"/>

            <corners android:bottomRightRadius="0dp"/>

            <gradient android:type="linear" android:angle="270" android:startColor="#ffffff" android:endColor="#ffffff"/>
        </shape>

    </rotate>
</item>
<item
    android:width="20dp"
    android:height="20dp"
    android:gravity="top|left">
    <rotate
        android:fromDegrees="45"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="45">
        <shape android:shape="rectangle">

            <corners android:bottomRightRadius="2dp"/>

            <gradient android:type="linear" android:angle="270" android:startColor="#ffffff" android:endColor="#ffffff"/>
        </shape>

    </rotate>
</item>
<item
    android:width="120dp"
    android:height="36dp"
    android:bottom="6dp">
    <shape android:shape="rectangle">

        <gradient
            android:angle="0"
            android:endColor="@color/white"
            android:startColor="@color/white"
            android:type="linear" />

    </shape>

</item>
</layer-list>
Respondeu 20/09/2018 em 05:09
fonte usuário

votos
0

Você criar forma em camadas como

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:width="120dp"
        android:height="36dp"
        >
        <shape>
            <padding
                android:bottom="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#20CCCCCC" />

            <corners android:radius="3dp" />
        </shape>
    </item>
    <item
        android:width="120dp"
        android:height="36dp"
        >
        <shape>
            <padding
                android:bottom="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#30CCCCCC" />

            <corners android:radius="3dp" />
        </shape>
    </item>
    <item
        android:width="120dp"
        android:height="36dp"
        >
        <shape>
            <padding
                android:bottom="1dp"
                android:right="1dp"
                android:top="1dp" />

            <solid android:color="#50CCCCCC" />

            <corners android:radius="3dp" />
        </shape>
    </item>
    <item
        android:width="20dp"
        android:height="20dp"
        android:gravity="top|left">
        <rotate
            android:fromDegrees="45"
            android:pivotX="70%"
            android:pivotY="40%"
            android:toDegrees="45">
            <shape android:shape="rectangle">
                <gradient android:type="linear" android:angle="270" android:startColor="#05CCCCCC" android:endColor="#05CCCCCC"/>
            </shape>

        </rotate>
    </item>

    <item
        android:width="20dp"
        android:height="20dp"
        android:gravity="top|left">
        <rotate
            android:fromDegrees="45"
            android:pivotX="70%"
            android:pivotY="40%"
            android:toDegrees="45">
            <shape android:shape="rectangle">
                <gradient android:type="linear" android:angle="270" android:startColor="#20CCCCCC" android:endColor="#20CCCCCC"/>
            </shape>

        </rotate>
    </item>
    <item
        android:width="20dp"
        android:height="20dp"
        android:gravity="top|left">
        <rotate
            android:fromDegrees="45"
            android:pivotX="60%"
            android:pivotY="45%"
            android:toDegrees="45">
            <shape android:shape="rectangle">
                <gradient android:type="linear" android:angle="270" android:startColor="#30CCCCCC" android:endColor="#30CCCCCC"/>
            </shape>

        </rotate>
    </item>
    <item
        android:width="20dp"
        android:height="20dp"
        android:gravity="top|left">
        <rotate
            android:fromDegrees="45"
            android:pivotX="50%"
            android:pivotY="50%"
            android:toDegrees="45">
            <shape android:shape="rectangle">

                <corners android:bottomRightRadius="2dp"/>

                <gradient android:type="linear" android:angle="270" android:startColor="#ffffff" android:endColor="#ffffff"/>
            </shape>

        </rotate>
    </item>

    <item
        android:top="1dp"
        android:width="120dp"
        android:height="36dp"
        android:bottom="5dp">
        <shape android:shape="rectangle">
            <gradient
                android:endColor="@android:color/white"
                android:startColor="@android:color/white"
                android:type="linear" />
        </shape>
    </item>

</layer-list>

saída:

digite descrição da imagem aqui

Respondeu 20/09/2018 em 05:01
fonte usuário

votos
0
**Try this:**

> **if you remove corner then delete <corners android:radius="@dimen/dp_5"/>  this line.**


    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:width="@dimen/dp_30"
            android:height="@dimen/font_20"
            android:gravity="top|left">
            <rotate
                android:fromDegrees="45"
                android:pivotX="60%"
                android:pivotY="80%"
                android:toDegrees="45">
                <shape android:shape="rectangle">

                    <corners android:bottomRightRadius="2dp"/>

                    <solid android:color="@color/white"/>
                </shape>

            </rotate>
        </item>
        <item
            android:width="120dp"
            android:height="36dp"
            android:bottom="6dp">
            <shape android:shape="rectangle">

                <corners android:radius="@dimen/dp_5"/>

                <solid android:color="@color/white"/>
            </shape>
        </item>
    </layer-list>
Respondeu 20/09/2018 em 04:43
fonte usuário

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more