我想改变我在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