I have tried changing the size of my button when I press it but nothing seem to work.
The button is created in main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_alignParentLeft="true"
android:layout_height="90px"
android:id="@+id/button1"
android:layout_marginTop="120px"
android:layout_width="90px"
android:textSize="45px"
android:textStyle="bold"
android:background="@drawable/bnumber"
android:text="1">
</Button>
And the code for the button logic is:
button1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
sendMessage("key1\n");
button1.setWidth(140);
button1.setHeight(140);
}
if(event.getAction() == MotionEvent.ACTION_UP) {
button1.setWidth(90);
button1.setHeight(90);
}
return false;
}
});
From googling I am quite sure this should work, but for some reason it doesn't.
My device uses Android 1.6, could this be the problem?
When you got the event ACTION_DOWN, if you return false, you couldn't get ACTION_UP event. Try change
to
onTouchListener
is used to handle motion events. Try usingonClickListener
instead.ACTION_UP and ACTION_DOWN are used to indicate gestures (see here), not pressing / releasing the button.
You can set button width and height using the following code to set button width and height
Thanks Deepak