我正在动态创建一个自定义视图,它是一个使用按钮、图像和线条的交互式流程图。我为每个元素创建一个子视图,然后将它们添加到主视图组。IE:
// lines
LineDrawView lineView = new LineDrawView(getActivity(),lineArray);
lineView.setClickable(false);
layout.addView(lineView);
然后我的按钮:
Button button = new Button(getActivity());
button.setText(title);
layout.addView(button, new AbsoluteLayout.LayoutParams(width, height, x, y));
我所有的布局参数都是预定义的,并存储在定义每个流程图的数据库中。除了我的台词外,我得到了我想要的效果。在某些情况下,我只画了一条线,我希望按钮位于这条线的顶部。相反,我的路线总是走在前列。IE:
我的问题是如何强制我的线视图在后台?这是我的线视图代码:
public class LineDrawView extends View {
private int KMULTIPLIER = 2;
private ArrayList<String []> lineArray;
public LineDrawView(Context context, ArrayList<String []> lineArray) {
super(context);
this.lineArray = lineArray;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);;
paint.setColor(Color.BLACK);
paint.setStrokeWidth(3);
// determine the screen size & initialize CONSTANT
int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
switch(screenSize) {
case Configuration.SCREENLAYOUT_SIZE_LARGE:
KMULTIPLIER = 4;
break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
KMULTIPLIER = 3;
break;
case Configuration.SCREENLAYOUT_SIZE_SMALL:
KMULTIPLIER = 2;
break;
default:
}
// draw the lines
if (lineArray.size() > 0) {
for (int i=0;i < lineArray.size();i++) {
String[] array = lineArray.get(i);
int x = Integer.parseInt(array[0].trim())*KMULTIPLIER;
int y = Integer.parseInt(array[1].trim())*KMULTIPLIER;
int x2 = Integer.parseInt(array[2].trim())*KMULTIPLIER;
int y2 = Integer.parseInt(array[3].trim())*KMULTIPLIER;
canvas.drawLine(x, y, x2, y2, paint);
}
}
}
}
任何建议将不胜感激。先谢谢了。