在电子邮件下方,用户将在密码下方输入电子邮件n,用户将输入密码,我可以制作正方形,但上方应为上侧曲线和下侧下方。
答案 0 :(得分:3)
我认为我会做出你想做的事情。您只需将它们添加到此Manager即可。请注意,我认为我没有补偿margin或padding之类的内容,所以你可以用paint()
方法计算它,或者只是将它包含在另一个具有正确填充/边距的Manager中:< / p>
public class GroupFieldManager extends VerticalFieldManager {
private int _rounding;
private int _bgColor;
private int _borderColor;
private boolean _divider;
private int _dividerColor;
public GroupFieldManager(boolean divider, long style) {
super(style);
_rounding = 20;
_bgColor = 0xFFFFFF;
_borderColor = 0xAAAAAA;
_divider = divider;
_dividerColor = 0xAAAAAA;
}
public GroupFieldManager(boolean divider) {
this(divider, 0);
}
public GroupFieldManager() {
this(false, 0);
}
/**
* Sets whether or not to draw a divider
* @param on
*/
public void setDivider(boolean on) {
_divider = on;
}
/**
* Sets the color for the divider (also turns divider on)
* @param color
*/
public void setDividerColor(int color){
_dividerColor = color;
_divider = true;
}
/**
* Sets the background color for the grouping
* @param color
*/
public void setBackgroundColor(int color) {
_bgColor = color;
}
/**
* Sets the border color for the grouping
* @param color
*/
public void setBorderColor(int color) {
_borderColor = color;
}
/**
* Sets the amount of rounding for the border
* @param rounding
*/
public void setRounding(int rounding) {
_rounding = rounding;
}
protected void paint(Graphics graphics) {
int oldColor = graphics.getColor();
//draw the background
graphics.setColor(_bgColor);
graphics.fillRoundRect(0, 0, getWidth(), getHeight(), _rounding, _rounding);
//draw the border
graphics.setColor(_borderColor);
graphics.drawRoundRect(0, 0, getWidth(), getHeight(), _rounding, _rounding);
//draw dividers
if(_divider) {
graphics.setColor(_dividerColor);
int y = 0;
//go through each field, figure it's height, and draw a line under it
for(int i=0;i<getFieldCount();i++) {
if(i != getFieldCount() - 1) {
int height = getField(i).getHeight();
y += height;
graphics.drawLine(0, y, getWidth(), y);
}
}
}
graphics.setColor(oldColor);
super.paint(graphics);
}
}
答案 1 :(得分:1)
由于只有可用于绘制四个圆角的方法,因此您可以使用剪切矩形将绘图剪切为直线,即您实际绘制一个较大的圆角矩形,但剪切它的下部(或上部)。 / p>