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