java - 怎么把边框变成卡通泡泡

标签 java android graphics border drawable

所以我想将布局的边框更改为漫画/卡通中的某种气泡。我知道我可以像这样更改边框:

<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape     android:shape="rectangle" >
            <corners  android:radius="5dip" />
            <stroke  android:width="2dip" android:color="@color/white"/>
        </shape>
    </item>
</layer-list>

但是我如何做尖头部分(看起来像三角形的部分)。我需要用它来指向我点击的内容。 我知道这听起来很奇怪或有趣,但我需要尝试一下。

最佳答案

不,你不能那样做。您可以提供描边角,但不能提供复杂的曲线(三角形),对于自定义形状,您可以在 onDraw() 中使用 view 和 onDraw()

Path path = new Path();
path.moveTo(160.0f, 240.0f);
path.lineTo(140.0f, 200.0f);
path.addArc(new RectF(140, 180, 180, 220), -180, 180);
path.lineTo(160.0f, 240.0f);
path.close(); 

这条路径将使用 Canvas 绘制,

canvas.drawPath(路径,绘画);

enter image description here

最好用9Patch概念来创建图像。 enter image description here

该工具将有助于轻松构建 9Patch 镜像 http://android.elex.pe.kr/a-better-9-patch-tool

关于java - 怎么把边框变成卡通泡泡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10306104/

相关文章:

java - Java 新手,想知道 Scanner 读取的 if 语句和字符串

java - 对于 HotSpot JIT, "already compiled into a big method"是什么意思?

Android 6.0 无提示自动获取权限

android - OpenGL ES2 : Vertex Indices and Texture coordinates?

java - 我的 java 程序意外停止正常工作

java - 将工作表添加到现有的 Excel 文件中

android - 我试图在 android studio 中单击时更改按钮属性,但不幸的是它停止了应用程序

java - 如何获取 View 的宽度和高度

math - 点到椭圆弧的最短距离算法

java - GWT SoundManager 2 play() 抛出异常