【问题标题】:Create triangle with rounded corners创建带圆角的三角形
【发布时间】:2016-10-04 13:11:19
【问题描述】:

我需要创建带圆角的三角形。这是我的代码

<item android:gravity="center">
    <rotate
        android:fromDegrees="45"
        android:pivotX="-40%"
        android:pivotY="87%"
        android:toDegrees="45" >
        <shape android:shape="rectangle" >
            <corners android:radius="2dp"/>
            <solid android:color="#ffffff" >
            </solid>

            <stroke
                android:color="#ffffff" />

        </shape>

    </rotate>
</item>

在我的代码中,只有三角形的一侧是圆角的,其他两个角不是圆角的。请帮我创建所有角的三角形。

【问题讨论】:

  • 您将此文件保存在哪个可绘制文件夹中?
  • 我只保存在可绘制文件夹中。
  • 您可以尝试为不同的 4 个属性应用半径吗?
  • 我也试了,不行
  • 使用 svg drawable 而不是简单的形状

标签: android draw shape


【解决方案1】:

创建triangle.xmlres/drawable

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:height="50dp"
        android:width="50dp"
        android:viewportHeight="16.0"
        android:viewportWidth="16.0" >
    <path android:fillColor="@color/colorAccent" 
          android:pathData="M11.844,9.04L8.345,5.163c-0.195,-0.217 -0.511,-0.217 -0.705,0l-0.012,0.02L4.136,9.04c-0.195,0.217 -0.195,0.569 0,0.786l0.006,0.005C4.233,9.936 4.358,10 4.499,10h6.983c0.143,0 0.27,-0.068 0.359,-0.176l0.002,0.002C12.039,9.609 12.039,9.257 11.844,9.04z"/>
</vector>

通过改变android:fillColor来改变三角形的颜色

并使用@drawable/triangle

这很简单.... 因为简单的drawable没有修改形状的高级功能。

【讨论】:

  • 如何更改 pathData 以设置更多圆角?
  • 使用InkscapeAdobe Illustrator 创建或修改svg。然后在您的 android ide 中从本地 svg 创建可绘制的矢量。
  • 1.打开Inkscape 2.绘制形状3.按Shift+Ctrl+S 4.选择普通SVG(*.svg) 5.保存。
  • 然后打开 link 将 SVG 转换为 VectorDrawable
  • Inkscape 肯定是 android studio 项目的必备工具,因为它很容易以足够快的速度创建所需的形状。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-20
  • 1970-01-01
  • 1970-01-01
  • 2017-12-04
  • 2012-10-20
  • 2016-08-09
相关资源
最近更新 更多