开发者

How to draw a resizable area

I would like to make an activity like set avatar in contact android application. I can resize the selec开发者_开发技巧tion area by touch to corner (up-left and bottom-right). How can I implement like that?

Please, give me advices.

Thank you very much.

Edit: I want it like this: It is like this picture

My problem is I don't know how to make event: touch, then drag the selection area.


You could use the crop function you mentioned. It will open the gallery where you can pick an image and select a certain area.

Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 96); 
intent.putExtra("outputY", 96);

try {
    intent.putExtra("return-data", true);
    startActivityForResult(intent, PICK_REQUEST);
}

catch (ActivityNotFoundException e) {
    new AlertDialog.Builder(OptionenActivity.this)
    .setTitle("Error")
    .setMessage("An error occured")
    .setPositiveButton(android.R.string.ok, null).show();
}

And get the result via onActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

    if (resultCode != RESULT_OK)
        return;

    switch (requestCode) {
        case PICK_REQUEST:
            final Bundle extras = imageReturnedIntent.getExtras();

            if (extras != null) {
                Bitmap image = extras.getParcelable("data");                    
                Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
            }
            break;
    }
}

Edit:

You'll get this:

How to draw a resizable area


oweride the onDraw method in a frame layout

now you have 2 options resize the frameLayout or change the size in the ondraw method

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜