使用手指触摸,在android上绘制ImageView

时间:2014-08-08 12:06:52

标签: android android-canvas android-imageview android-drawable

尝试开发一个应用程序,用户可以用手指在图像视图上绘图。我想要的是用户可以使用按钮更改imageView图像。到目前为止,我可以通过点击下一个和上一个按钮来编码图像更改逻辑,有人可以使用手指触摸帮助我绘制部件,用户可以通过按钮单击清除。 下面是我已经工作过的代码

public class MainActivity extends Activity {

    int images[] = { R.drawable.party1, R.drawable.party2, R.drawable.party3,
            R.drawable.party4, R.drawable.party5, R.drawable.party6,
            R.drawable.party7, R.drawable.party8, R.drawable.party9,
            R.drawable.party10 };
    ImageView hImageViewPic;
    Button btn_perv, btn_next;
    private int currentImage = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn_next= (Button) findViewById(R.id.button_next);
        btn_perv = (Button) findViewById(R.id.button_previous);
        hImageViewPic = (ImageView) findViewById(R.id.imageView1);
        btn_next.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                currentImage++;
                currentImage = currentImage % images.length;

                hImageViewPic.setImageResource(images[currentImage]);
            }
        });

        btn_perv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                 currentImage--;
                    currentImage = (currentImage + images.length) % images.length;

                    hImageViewPic.setImageResource(images[currentImage]);
            }
        });

    }
}

0 个答案:

没有答案