9补丁的多个阴影层?

时间:2020-11-10 11:40:26

标签: android layer shadow nine-patch

我正在尝试在按钮上实现this的外观。我尝试了几件事,但没有一件事奏效。我的最后一个解决方案是创建9个补丁的图像(一个图像用于左上角的光影层,另一个图像用于右下角的暗影层),并将它们组合到一个可绘制的资源文件中。像这样:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/solids">
    <nine-patch android:src="@drawable/bottom" android:dither="false" />
</item>
<item android:id="@+id/solid">
    <nine-patch android:src="@drawable/shadow1" android:dither="false" />
</item>

</layer-list>

但是它们不合适。它们看起来像this:/有人可以帮我吗?非常感谢!

编辑:另外,我还需要另外9个补丁来绘制我的cardview。在我的设计中,有一张像this这样的卡片。我从Adobe xd here获得了有关此卡的详细信息,当我按照它的确切说明进行操作时,它不合适。变得像this,我该如何解决?

编辑2:This是我的Cardview的9补丁文件。这里是我的用法:

<androidx.cardview.widget.CardView
                android:id="@+id/myCard"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginTop="40dp"
                app:cardCornerRadius="20dp"
                app:layout_constraintEnd_toEndOf="@+id/card1"
                app:layout_constraintHeight_percent="0.25"
                app:layout_constraintHorizontal_bias="0.512"
                app:layout_constraintStart_toStartOf="@+id/card1"
                app:layout_constraintTop_toBottomOf="@+id/card1"
                app:layout_constraintWidth_percent="0.90">

                <androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/myNinePatch"/>

</androidx.cardview.widget.CardView>

注意:我不是母语人士,所以我尽力解释了一切。

0 个答案:

没有答案
相关问题