更改按钮的位置 [英] Changing position of a button
本文介绍了更改按钮的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个AbsoluteLayout一个按钮在XML文件中。从那里,我能够设置按钮(X,Y)的位置。
I have one button in an AbsoluteLayout in an XML file. From there I am able to set the (x,y) position of the button.
我怎样才能获取和设置(X,Y)坐标按钮编程?
How can I get and set the (x,y) coordinates of the button programmatically?
谢谢大家。
推荐答案
您必须通过调用<一个得到一个参考给你按键,例如href="http://developer.android.com/reference/android/app/Activity.html#findViewById%28int%29">findViewById().当你得到了参照按钮,你可以设置x和y的值按钮的 setX的()和按钮。塞蒂()
You have to get a reference to you button, for example by calling findViewById(). When you got the reference to the button you can set the x and y value with button.setX() and button.setY().
....
Button myButton = (Button) findViewById(R.id.<id of the button in the layout xml file>);
myButton.setX(<x value>);
myButton.setY(<y value>);
....
这篇关于更改按钮的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文