我创建了fingerpaint app。来自finger paint android示例API。 (样本:http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/2.2_r1.1/com/example/android/apis/graphics/FingerPaint.java)
现在我已经创建了一个从paint(和move)创建位图的函数。这是我的代码:
public void addProgrammatlyImage(int pos[], String filePath){
// Let's create the missing ImageView
ImageView image = new ImageView(this);
// Now the layout parameters, these are a little tricky at first
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
image.setScaleType(ImageView.ScaleType.MATRIX);
Bitmap selectedImage = BitmapFactory.decodeFile(filePath);
image.setImageBitmap(selectedImage);
image.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
System.out.println("TOUCH!!");
switch(event.getActionMasked())
{
case MotionEvent.ACTION_DOWN:
offset_x = (int)event.getX();
offset_y = (int)event.getY();
selected_item = v;
break;
default:
break;
}
return false;
}
});
// Let's get the root layout and add our ImageView
FrameLayout layout = (FrameLayout) findViewById(R.id.vg1);
layout.setBackgroundColor(getResources().getColor(R.color.xxx));
layout.bringToFront();
((FrameLayout) layout).addView(image, 0, params);
}
我的问题是:
如果在同一级别的指纹视图(样本中的MyView类)上充气新图像,则在背景上消失(指纹位于图像前方)。
我无法插入图像作为MyView的子项。在这种情况下,当图像膨胀时出现问题:classcast exception
,无法将视图(MyViewClass)投射到ViewGroup
。
你能帮帮我吗?