[英]how to create triangle custom shape android
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="40dp"
android:viewportHeight="100"
android:viewportWidth="100">
<group android:name="triableGroup">
<path
android:name="triangle"
android:fillColor="@color/colorPrimary"
android:pathData="m 0,0 l 100,0 -100,100 z" />
</group>
</vector>
我想創建這種類型的形狀。 但我累了。
你可以用 vector drawable 試試這個:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path android:pathData="M0,0 L24,0 L0,24 z"
android:strokeColor="@color/color"
android:fillColor="@color/color"/>
</vector>`
您可以將矢量用於三角形形狀。 這是我的三角形矢量代碼
三角形.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M0,12l0,12 11.5,-5.7c6.3,-3.2 11.5,-6 11.5,-6.3 0,-0.3 -5.2,-3.1 -11.5,-6.3l-11.5,-5.7 0,12z"
android:strokeColor="#00000000"
android:fillColor="#000000"/>
將上述文件放在 drawable 文件夾中。 現在在您的 xml 中使用以下代碼,
<ImageView
android:id="@+id/ivTriangle"
android:layout_width="@dimen/_100sdp"
android:layout_height="@dimen/_100sdp"
android:rotation="270"
android:background="@drawable/triangle" />
您可以將以下代碼用於您的三角形類型。
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:background="@android:color/white"
android:layout_width="@dimen/_100sdp"
android:layout_height="@dimen/_100sdp"/>
<androidx.cardview.widget.CardView
android:layout_margin="@dimen/_1sdp"
app:cardBackgroundColor="@android:color/transparent"
app:cardCornerRadius="@dimen/_100sdp"
android:layout_width="@dimen/_200sdp"
android:layout_height="@dimen/_200sdp">
</androidx.cardview.widget.CardView>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.