
我想做一個這樣的按鈕。我使用cardview來給出半徑和陰影效果。但只有投影不會像上圖那樣給人一種前衛的風格。這是我創建此類按鈕的代碼:
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginEnd="10dp"
app:cardCornerRadius="20dp"
app:cardBackgroundColor="@color/tuna2"
app:strokeColor="@color/gun_powder"
app:cardElevation="6dp"
app:contentPadding="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:id="@ id/textView28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/transfer"
android:textColor="@color/white"
android:layout_marginStart="30dp"
android:layout_marginEnd="37dp"
android:fontFamily="@font/dm_sans"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@ id/imageView23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
app:layout_constraintBottom_toBottomOf="@ id/textView28"
app:layout_constraintStart_toEndOf="@ id/textView28"
app:layout_constraintTop_toTopOf="@ id/textView28"
app:srcCompat="@drawable/ic_arrow_right" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
此代碼創建一個按鈕,如下圖所示:

如何使按鈕看起來像太陽從上方照射?
uj5u.com熱心網友回復:
嘗試這個
可繪制/custom_bg.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="#41445F"/>
<corners android:radius="20dp"/>
<size android:width="100dp" android:height="40dp"/>
</shape>
</item>
<item android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="#303348"/>
<corners android:radius="20dp"/>
<size android:width="100dp" android:height="40dp"/>
</shape>
</item>
</layer-list>
ConstraintLayout并像這樣在布局中設定背景
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/custom_bg">
像這樣輸出

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/506294.html
標籤:安卓 安卓布局 用户界面 android-cardview 阴影
