[英]Create custom keyboard in android using different layout and keys not being rectangle, shape picked from the drawable image
[英]android create custom shape layout
我需要创建ViewGroup自定义形状。 它可能是FrameLayout.It应该看起来像
它必须是ViewGroup,因为我需要在其中添加文本或图像。我该怎么做? 非常感谢。
这里有一个很好的教程,介绍如何创建自定义多边形形状。 这是一个相当长的过程,但是您会到达那里。 简而言之,您将必须为自定义View
创建自定义XML属性。
真正的魔力在这里:
@Override
protected void onDraw(Canvas canvas) {
int measuredWidth = getMeasuredWidth();
int measuredHeight = getMeasuredHeight();
int x = (measuredWidth/2) ;
int y = (measuredHeight/2) ;
int radius = Math.min(x,y) ;
if (sides < 3) return;
float a = (float) (Math.PI * 2)/sides;
int workingRadius = radius;
polyPath.reset();
// The poly is created as a shape in a path.
// If there is a hole in the poly, draw a 2nd shape inset from the first
for(int j = 0; j < ((fillPercent < 100) ? 2 : 1) ; j++){
polyPath.moveTo(workingRadius,0);
for (int i = 1; i < sides; i++) {
polyPath.lineTo((float)(workingRadius*Math.cos(a*i)),
(float)(workingRadius*Math.sin(a*i)));
}
polyPath.close();
workingRadius -= radius * fillPercent;
a = -a;
}
canvas.save();
canvas.translate(x, y);
canvas.rotate(startAngle);
canvas.drawPath(polyPath, fillPaint);
canvas.restore();
if(showInscribedCircle){
canvas.drawCircle(x,y,radius, inscribedCirclePaint);
}
super.onDraw(canvas);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.