2

我已经创建了手指画应用程序。来自手指画 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。爪哇)

现在我创建了一个函数来从绘画(和移动)创建位图。这是我的代码:

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

你能帮我吗??

4

0 回答 0