【问题标题】:Create a rectangle with triangle drawable android?用三角形可绘制的android创建一个矩形?
【发布时间】:2015-08-27 23:00:48
【问题描述】:

我需要根据下图创建一个可绘制的形状 XML,其中我们在上边的中间有一个三角形。

我知道如何创建一个矩形和一个三角形

可绘制矩形

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="2dp" android:color="#ff207d94" />
<padding android:left="2dp"
    android:top="2dp"
    android:right="2dp"
    android:bottom="2dp" />
<corners android:radius="5dp" />
<solid android:color="#ffffffff" />
</shape>

可绘制三角形

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
    <rotate
        android:fromDegrees="45"
        android:toDegrees="45"
        android:pivotX="-40%"
        android:pivotY="87%" >
        <shape
            android:shape="rectangle"  >
            <stroke android:color="@android:color/transparent" android:width="10dp"/>
            <solid
                android:color="#000000"  />
        </shape>
    </rotate>
</item>
</layer-list>

如何使用它们来创建图像?

【问题讨论】:

  • 创建一个 .9.png 可绘制对象
  • 请不要使用这种“怪物般”的 xml 文件:layer-list>rotate>shape,使用九个补丁可绘制或自定义 Shapeclass 与 ShapeDrawable 一起使用

标签: android xml drawable shape


【解决方案1】:

这里好像有一个9补丁像这个小东西

真的是你要找的东西:

只需给它.9.png 扩展名。
有关 9 个补丁的精彩指南,请参阅:http://radleymarx.com/blog/simple-guide-to-9-patch/

【讨论】:

  • 我同意,您可以使用 xml 可绘制对象来实现,但这并不能保证它在每个设备上都看起来不错
  • 而且我想找到一张完美的收据会有点困难。也许在渲染方面也更难。
猜你喜欢
  • 1970-01-01
  • 2015-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多