10
A
回答
12
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="292dp"
android:height="172dp"
android:viewportWidth="292"
android:viewportHeight="172">
<path
android:strokeWidth="1.5"
android:strokeMiterLimit="10"
android:pathData="M 27.046 96.615 L 16.416 150.396 L 271.534 150.396 L 186.495 22.836 L 37.676 22.836 L 27.046 86.615 Z" />
<path
android:fillColor="#00ff00"
android:strokeWidth="1.5"
android:strokeMiterLimit="10"
android:pathData="M 16.046 20.615 L 13.416 150.396 L 271.534 150.396 L 186.495 22.836 L 37.676 22.836 L 16.046 23.615 Z " />
</vector>
+0
我推荐这个答案。看到我的答案[这里](http://stackoverflow.com/a/42145439/7292819)链接到文档和一个例子,这将给如何使用这个更多的想法。 – Gary99 2017-03-28 01:22:52
+0
对不起我的问题,但你为什么第一次使用
2
您可以尝试在代码或xml中制作LayerDrawable
。做一个矩形和一个三角形 退房的开发者网站获取更多信息:http://developer.android.com/reference/android/graphics/drawable/LayerDrawable.html
2
这个类是一个View
定义,并绘制一个梯形ShapeDrawable
。因此,梯形,作为Drawable
,也可用于背景。
package com.stackoverflow.questions.q25768037;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.PathShape;
import android.util.AttributeSet;
import android.view.View;
public class TrapezoidView extends View {
private ShapeDrawable mTrapezoid;
public TrapezoidView(Context context, AttributeSet attrs) {
super(context, attrs);
Path path = new Path();
path.moveTo(0.0f, 0.0f);
path.lineTo(100.0f, 0.0f);
path.lineTo(200.0f, 100.0f);
path.lineTo(0.0f, 100.0f);
path.lineTo(0.0f, 0.0f);
mTrapezoid = new ShapeDrawable(new PathShape(path, 200.0f, 100.0f));
mTrapezoid.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
mTrapezoid.getPaint().setStrokeWidth(1.0f);
mTrapezoid.getPaint().setColor(Color.GREEN);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mTrapezoid.setBounds(0, 0, w, h);
}
@Override
protected void onDraw(Canvas canvas) {
mTrapezoid.draw(canvas);
}
}
相关问题
- 1. 如何合并两个形状在一个梯度的Android
- 2. 双梯形形状
- 3. 如何创建从一个形状到另一个形状的变形效果?
- 4. Android的形状 - 梯度应到右侧
- 5. 创建形状与CSS梯度
- 6. 阴影与CSS梯形形状按钮
- 7. 带文本的CSS梯形形状
- 8. 制作梯形标签形状
- 9. Visio:如何获取包含在一个形状中的形状?
- 10. 在C#上构造一个形状为环的形状
- 11. 在Android中移动一个形状
- 12. 建立一个形状类三角形
- 13. 在Java中打印一个梯形
- 14. Android:在另一个形状内绘制形状
- 15. android形状内的形状
- 16. 在另一个矩形内创建一个形状
- 17. 当形状部分透明时,如何在Canvas中从另一个形状(XOR)切出一个形状?
- 18. 如何让形状创建一个圆形?
- 19. 如何将Sprite变形为梯形?
- 20. 如何在Android中绘制形状
- 21. 如何在PHP中实现梯形法?
- 22. 梯度上的一个矩形在QML
- 23. Slick2d形状包含另一个形状
- 24. 如何在UITableViewCell中创建一个圆形状?
- 25. 如何在draw.io中创建一个固定大小的形状?
- 26. 使用android.graphics.Path从另一个形状中删除一个形状
- 27. android中的形状
- 28. 如何在android xml中绘制三角形形状
- 29. 在java中打印'*'梯形
- 30. 在opengl中翻译另一个形状内的形状
使用std用自定义形状 – pskink 2014-09-10 14:49:50
使用矢量绘制ShapeDrawable:见我的回答如下。 – 2017-03-21 13:50:47
检查这个[答案](http://stackoverflow.com/questions/41551094/how-to-create-leaning-list-items/41622884#41622884) – 2017-03-23 12:28:58