【发布时间】:2011-05-31 06:48:03
【问题描述】:
我尝试在按下按钮时更改按钮的大小,但似乎没有任何效果。
按钮在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,这可能是问题所在吗?
【问题讨论】: