我想使用 View 創建一個具有以下設計的自定義按鈕,并給它一個像下面設計的陰影。1
陰影選項是: box-shadow: 10px 7px 25px 0px #0000001F
- main_round_teamsbtn.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:padding="10dp"
android:shape="rectangle">
<solid android:color="@color/btn_color" />
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="105dp" />
</shape>
</item>
</layer-list>
- team_main_btn.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
android:orientation="vertical"
android:background="@drawable/main_round_teamsbtn"
android:paddingStart="16dp">
<TextView
android:id="@ id/teamsHead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/notosans_bold"
android:includeFontPadding="false"
android:text="???\n????\n?????"
android:textColor="@color/black"
android:textSize="22sp"
app:layout_constraintBottom_toTopOf="@ id/teamsSub" />
<TextView
android:id="@ id/teamsSub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/notosans_regular"
android:text="?? ??? ?? ? ????"
android:textColor="#8C8C8C"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent" />
<ImageView
android:id="@ id/teamsImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:background="@drawable/findteams_btn"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0" />
</androidx.constraintlayout.widget.ConstraintLayout>
- 主檔案
...
<com.example.moizar.MainTeamsBtnView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
...
我想要一個答案如何給陰影
uj5u.com熱心網友回復:
我懷疑您能否通過代碼實作您想要的功能,即使這是可能的,您也會撰寫大量代碼,可能涉及RenderScript或 Android 12 上的一些新 API ......
考慮將您的影像用作9-patch drawable,并帶有正確標記的內容/拉伸區域。內容(文本?)將是全高和半寬,拉伸區域只有第一個像素
uj5u.com熱心網友回復:
- team_main_btn.xml
您可以elevation在 TextView 或 ImageView 中使用屬性。
機器人:海拔=“10dp”
您可以觀看此鏈接了解更多資訊:
https://www.youtube.com/watch?v=nNHChjTZCtw&ab_channel=CodeAndDesign
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/361496.html
