我想改變我在d applcn按鈕餘量... 假設我有5個按鈕這樣的直鏈佈局中,一個下面d其他.. 。改變X和按鈕的按鈕/改變餘量的Y位置動態
當我專注於一個按鈕,其寬度應加大(我知道如何處理),並在同一時間,寬度應朝左側和右側線性增加。
ie如果按鈕的當前寬度爲250,x座標爲50(表示按鈕的左邊爲50,按鈕的右邊爲300),當我關注按鈕時,我應該得到x座標爲75 (左= 25和右= 325)。如何更改按鈕的邊距/ x座標?
我想改變我在d applcn按鈕餘量... 假設我有5個按鈕這樣的直鏈佈局中,一個下面d其他.. 。改變X和按鈕的按鈕/改變餘量的Y位置動態
當我專注於一個按鈕,其寬度應加大(我知道如何處理),並在同一時間,寬度應朝左側和右側線性增加。
ie如果按鈕的當前寬度爲250,x座標爲50(表示按鈕的左邊爲50,按鈕的右邊爲300),當我關注按鈕時,我應該得到x座標爲75 (左= 25和右= 325)。如何更改按鈕的邊距/ x座標?
查看Animation
和ScaleAnimation
類別http://developer.android.com/reference/android/view/animation/Animation.html和http://developer.android.com/reference/android/view/animation/ScaleAnimation.html。
其中一種方法是在res/anim
目錄中定義兩個XML文件,一個用於放大按鈕,另一個用於縮小按鈕大小。因此,對於makeLarger.xml
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1"
android:toXScale="1.1"
android:pivotX="50%"
android:pivotY="50%"
android:duration="200"
android:fillAfter="true" />
在這裏,你會增加10%的寬度,從1.0到1.1。對於makeSmaller.xml
文件,交換的android:fromXScale
和android:toXScale
值,或只是將它們設置爲你喜歡。將動畫應用到您的按鈕,
Button myButton = (Button)findViewById(R.id.myButton);
myButton.setAnimation(AnimationUtils.loadAnimation(this, R.anim.makeLarger));
當然,makeLarger和makeSmaller動畫應該當你觸摸鍵設置。
我希望這有助於!
cos ...它確實幫助..很多很多...... :-) – mdv 2010-09-27 10:42:10