我想更改 d applcn 中按钮的边距...
假设我有 5 个这样的线性布局按钮,一个在另一个下面...
当我专注于一个按钮时,它的宽度应该增加(我知道如何处理),同时,宽度应该向两者线性增加左右。
即如果按钮的当前宽度为 250,x 坐标为 50(这意味着按钮的左侧为 50,按钮的右侧为 300),当我聚焦于按钮时,我应该得到 x 坐标为 75(左侧 = 25)右 = 325)。如何更改按钮的边距/x 坐标?
I would like to change margin of my buttons in d applcn...
suppose I have 5 buttons like this in a linear layout, one below d other...
When I focus on a button, its width should increase (which I know how to handle) and at the same time, width should increase linearly towards both left and right.
i.e. If the current width of the button is 250 with x co-ordinate as 50 (that means button's left is 50 and button's right is 300), when I focus on the button I should get x co-ordinate as 75 (left = 25 and right = 325). How to change the margin/x co-ordinate of the button?
发布评论
评论(1)
查看 Animation 和
ScaleAnimation
类="nofollow">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
此处,您将宽度增加 10%,从 1.0 增加到 1.1。对于
makeSmaller.xml
文件,交换android:fromXScale
和android:toXScale
的值,或者根据需要设置它们。要将动画应用到按钮,当然,当您触摸按钮时应该设置 makeLarger 和 makeSmaller 动画。
我希望这有帮助!
Check out the
Animation
andScaleAnimation
classes at http://developer.android.com/reference/android/view/animation/Animation.html and http://developer.android.com/reference/android/view/animation/ScaleAnimation.html.One way to do it is to define two XML files in your
res/anim
directory, one to make the button larger, and the other to make it smaller. So formakeLarger.xml
Here, you're increasing the width by 10%, from 1.0 to 1.1. For the
makeSmaller.xml
file, swap the values ofandroid:fromXScale
andandroid:toXScale
, or just set them as you like. To apply the animation to your button,Of course, the makeLarger and makeSmaller animations should be set when you touch the button.
I hope this helps!