如何在我的自定义类的特定位置添加图像视图到我的相对布局,扩展相对布局并使该图像视图可拖动到特定的布局部分?
下面是我想要添加图像的自定义类
那么,我应该在画布视图上添加图像还是仅仅在相对布局上添加?
请给我一个合适的解决方案。
public class CustomCompassView extends RelativeLayout {
int width;
int height;
int saparationRatio;
int captureRange;
private ImageView mImage;
public CustomCompassView(Context context) {
super(context);
}
public CustomCompassView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public CustomCompassView(Context context, AttributeSet attrs) {
super(context, attrs);
mImage = (ImageView) getChildAt(2);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
width = this.getWidth();
height = this.getHeight();
saparationRatio = (width / 2) / 5;
Log.e(AppConstant.LOG_TAG, "height: " + height + " & width: " + width);
drawCircleAbove125(canvas);
}
protected void drawCircleAbove125(Canvas canvas) {
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.FILL);
paint.setStrokeWidth(0.0f);
canvas.drawCircle(width / 2, height / 2, width / 2, paint);
}
答案 0 :(得分:0)
在相对布局类中夸大布局
LayoutInflater inflater = LayoutInflater.from (context);
View v = inflater.inflate (R.layout.some_file, null, true);
this.addView (v);
您可以在充气布局中添加任何您喜欢的内容。