【问题标题】:how to create triangle custom shape android如何创建三角形自定义形状android
【发布时间】:2019-12-12 05:15:30
【问题描述】:
<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>

我想创建this type of shape。但是我累了。

【问题讨论】:

    标签: android xml android-vectordrawable


    【解决方案1】:

    你可以用矢量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>`
    

    【讨论】:

    【解决方案2】:

    您可以将矢量用于三角形。这是我的三角向量代码

    triangle.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" />
    

    【讨论】:

    • 此代码无法根据我的问题 drive.google.com/open?id=1kyOwLIYqcdcAmFKqcxQYpedwXarX3iSj
    【解决方案3】:

    您可以将以下代码用于您的三角形类型。

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多