我試圖在 Android XML (Kotlin) 中獲得一個矩形形狀,使其具有倒置的右上角邊框。通過這個,我的意思是,而不是向左彎曲的圓形右上角邊框,我希望它向右四舍五入,就像一個尖點,然后再穿過頂部到左上角。
為了解釋我的意思,請在下面找到一些螢屏截圖。
到目前為止我有什么

我的目標是什么

到目前為止,就代碼而言,使用 Stack Overflow 上其他地方的一些示例,我生成了以下代碼。這是一個非常簡單的白色形狀,邊框左上角半徑,放置在綠色背景形狀的頂部,綠色形狀的右側。
<?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="@color/rsMoving"/>
</shape>
</item>
<item android:left="200dp" android:right="30dp" >
<shape android:shape="rectangle">
<solid android:color="@color/rsMoving" />
</shape>
</item>
<item android:left="200dp" android:right="0dp" >
<shape android:shape="rectangle">
<corners
android:topLeftRadius="50dp"/>
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
在研究方面,我看過一些例子,比如
左側和頂部的黑條標識可以擴展以增加可繪制物件的區域。右側和底部欄標識可以放置文本的位置。使用此 XML:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:backgroundTint="@android:color/darker_gray">
<TextView
android:id="@ id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/sample"
android:text="This is some wider text!"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@ id/textView2"
app:layout_constraintTop_toBottomOf="@ id/textView2" />
<TextView
android:id="@ id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/sample"
android:text="This is some text!"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@ id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
</androidx.constraintlayout.widget.ConstraintLayout>
我們看到以下

Android Studio (Arctic Fox 2020.3.1 Patch 2) 不能正確顯示這個 9-patch,但它在模擬器上顯示如下。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/326276.html
