简体   繁体   English

如何创建三角形自定义形状android

[英]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>

I want to to create this type of shape .我想创建这种类型的形状 But i tired.但我累了。

You can try this with vector drawable:你可以用 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>`

You can use vector for triangle shape.您可以将矢量用于三角形形状。 Here is my code for triangle vector这是我的三角形矢量代码

triangle.xml三角形.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"/>

Put above file in drawable folder.将上述文件放在 drawable 文件夹中。 Now in your xml use below code,现在在您的 xml 中使用以下代码,

<ImageView
    android:id="@+id/ivTriangle"
    android:layout_width="@dimen/_100sdp"
    android:layout_height="@dimen/_100sdp"
    android:rotation="270"
    android:background="@drawable/triangle" />

You can use below code for your type of 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM