I am new to android. I want to create my own custom buttons in android;The methods which I have used to create the custom buttons are; 1. Draw a simple image whatever you want in paint and then go to drawable resources then paste that image.From there, we can use those images as buttons. Suppose my image is like this,
I made the rest of the portion of this image excluding green TRANSPARENT so that i will make only the green area touchable,for this I am using this code,
Bitmap TheBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.green);
int eventPadTouch = event.getAction();
int iX = (int) event.getX();
int iY = (int) event.getY();
int[] location = new int[2];
v.getLocationOnScreen(location);
int viewX = location[0];
int viewY = location[1];
switch (eventPadTouch) {
case MotionEvent.ACTION_DOWN:
if (iX>=viewX & iY>=viewY & iX<=(viewX+TheBitmap.getWidth()) & iY<=(viewY+TheBitmap.getHeight())) {
if (TheBitmap.getPixel(iX,iY)!=0) {
Intent intent = new Intent(this, NewActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
showPressedState();
return false;
}
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
showNormalState();
break;
}
return true;
}
But when I am making this image like this, I am facing problem that THE below the curve portion in the image it is touchable again but i made it non touchable. and when I move to the next problem that if I want to create this kind of button I want to make all the portions to be used as buttons so that i can perform different activities on that,is it possible?
I found that this all is happening because android provides only limited types of layouts like LINEAR LAYOUT,RELATIVE LAYOUT,WEBVIEW. So ,is there any way to define our own layout means if i will be able to give the boudries of the layout.