Мне нужно создать такую ​​кнопку - PullRequest
0 голосов
/ 12 мая 2018

https://drive.google.com/open?id=1yOkIr0uu6iqwjin2_H00K7gkP_f7g1_r

Пожалуйста, помогите мне, как создать такую ​​кнопку с тенью красного цвета

Ответы [ 2 ]

0 голосов
/ 12 мая 2018

Попробуйте это

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    tools:context=".activity.SplashActivity">

    <Button
        android:layout_width="match_parent"
        android:background="@drawable/aa"
        android:layout_height="wrap_content" />



</LinearLayout>

Android: фон = "@ вытяжке / аа"

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

    </item>
    <item>
        <shape android:shape="rectangle" android:padding="10dp">
            <corners android:radius="40dp" />
            <gradient
                android:angle="45"
                android:endColor="#3cff00"
                android:startColor="#ff00ff"
                android:type="linear" />
            <padding
                android:bottom="0dp"
                android:left="0dp"
                android:right="0dp"
                android:top="0dp" />
        </shape>
    </item>

</layer-list>

андроид: рисую = "@ вытяжка / shadow_bg"

enter image description here

OUTPUT

enter image description here

ПРИМЕЧАНИЕ: Вы можете использовать Android 9-patch shadow generator для создания 9-патч-образа в соответствии с требованием

0 голосов
/ 12 мая 2018

Вам просто нужно использовать CardView для такого теневого фона

добавить библиотеку ниже

implementation 'com.android.support:design:26.1.0'  //support design

compile 'com.android.support:cardview-v7:26.1.0'   // CardView

в вашем xmlмакет объявления карты

<android.support.v7.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        card_view:cardBackgroundColor="#C8242A"
        card_view:cardCornerRadius="15dp"
        card_view:cardElevation="10dp">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                style="@style/TextAppearance.AppCompat.Small"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingBottom="5dp"
                android:paddingLeft="40dp"
                android:paddingRight="40dp"
                android:paddingTop="5dp"
                android:text="Sign in"
                android:textColor="#fff" />
        </LinearLayout>
    </android.support.v7.widget.CardView> 
...