简体   繁体   English

如何在android中绘制复杂的形状,包含三角形,矩形和笔划

[英]How to draw complicated shape in android, with contain of triangle, rectangle and stroke

I have a task to create chat. 我有创建聊天的任务。 Here is the UI: 这是UI:

在此输入图像描述

I've tried to draw rectangle and triangle and in layer list to combine this 2 drawables, but it looks very bad... 我试图绘制矩形和三角形,并在图层列表中组合这两个drawable,但它看起来非常糟糕...

Rectangle.xml Rectangle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">

    <corners android:radius="50dp"/>
    <solid android:color="@color/message_cloud_client" />
    <stroke android:color="@color/message_cloud_client_stroke" android:width="1dp"/>

</shape>

Triangle.xml Triangle.xml

<?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="90%" >
            <shape
                android:shape="rectangle"  >
                <stroke android:color="@android:color/transparent" android:width="10dp"/>
                <solid
                    android:color="#dce7f7"  />
            </shape>
        </rotate>
    </item>
</layer-list>

You can do this using Nine-patch images instead of creating a layer-list. 您可以使用Nine-patch图像而不是创建图层列表来执行此操作。 In a `Nine-patch' image you can indicate the rectangle that is grown or shrink when the image is resized. 在“九贴片”图像中,您可以指示调整图像大小时生长或缩小的矩形。 But the whole image is not affected. 但整个图像不受影响。 Here is the address of the tool: 这是该工具的地址:

sdk\\tools\\draw9patch

Open the file. 打开文件。 Import your original image and set a rectangle inside the original images that is affected when the image is resized. 导入原始图像并在调整图像大小时受影响的原始图像内设置矩形。 (Do not include the edges of your picture). (不要包括图片的边缘)。

Also you can do this with Vector images that is now available in support library. 您也可以使用支持库中现有的Vector图像来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何绘制具有可变笔触宽度的Android Shape Rectangle - How to draw a Android Shape Rectangle with variable stroke width 如何绘制附加到矩形的三角形? - How to draw a triangle shape attached to a Rectangle? 如何在Android画布上的自定义形状上绘制笔触 - How to draw stroke on custom shape on android canvas Android如何以编程方式创建三角形和矩形形状? - Android how to create triangle and rectangle shape programmatically? 如何在xml drawable android中绘制矩形内部内部末端三角形形状? - How to draw a rectangle inner inside end triangle shape in xml drawable android? Android如何以编程方式绘制圆角矩形形状 - Android how to draw Rounded Rectangle shape programmatically 如何以编程方式更改形状矩形的笔触宽度 - How to change the stroke width of a shape rectangle programmatically Android使用Canvas中的Stroke绘制自定义形状 - Android Draw the customized Shape using Stroke in Canvas 如何绘制三角形形状并将其添加到相对或线性布局android - How to draw triangle shape and add it into relative or linear layout android 如何设置笔触颜色以在画布上绘制矩形? - How to set stroke color to draw a rectangle on canvas?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM