我嘗試在按按鈕時更改我的按鈕的大小,但似乎沒有任何工作。在Android中按下時更改按鈕大小的問題
該按鈕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>
而且按鈕邏輯的代碼是:
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;
}
});
從谷歌上搜索我敢肯定這應該工作,但由於某種原因它沒有。
我的設備使用Android 1.6,這可能是問題嗎?
這正是我正在尋找的,謝謝! – 2011-05-31 10:02:50
非常歡迎 – 2011-05-31 10:10:02