我想为我的按钮使用背景。但是当我使用 png 时,它会减慢应用程序的速度。因此我想使用 xml 形状,但我不知道如何切角(如图所示)。
现在我有以下形状,它只是一个矩形:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/blue_semi_transparent"/>
<padding android:bottom="10dp" android:right="10dp" android:top="10dp" android:left="10dp"/>
<margin android:bottom="10dp" android:right="10dp" android:top="10dp" android:left="10dp"/>
</shape>
如何绘制右下角?
最佳答案
你可以试试这个,
skewed_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#3F8EEB" />
</shape>
</item>
<item>
<rotate
android:fromDegrees="110"
android:pivotX="90%"
android:pivotY="90%"
>
<shape android:shape="rectangle" >
<solid android:color="#FFF" />
</shape>
</rotate>
</item>
</layer-list>
sample_layout.xml
<?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:padding="16dp"
android:orientation="vertical" >
<View
android:layout_width="200dp"
android:layout_height="50dp"
android:background="@drawable/triangle1"/>
</LinearLayout>
如果要修改倾斜区域只需要修改skewed_background.xml中第二项的fromDegrees、pivotX和pivotY的值。
关于Android:绘制带有斜角的形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44564304/