在2.3.3中放置坐标按钮android
问题描述:
我创建了一个应该随机放几个按钮(或imageview)的应用程序,我传递最大值和最小值,并从那里取坐标。在2.3.3中放置坐标按钮android
问题是,在4.2.2编译是完美的,但我寻求为2.3.3工作,因为我想分享我的应用程序在谷歌播放。
我使用的是android 4.2.2。做应用程序。
button.setX()和button.setY()
但在安卓2.3.3(API级别10)可以使用的方法
你知道我怎么会在API级别10?
非常感谢!
答
你应该看看这个答案:
https://stackoverflow.com/a/12195999/2140191
//The WRAP_CONTENT parameters can be replaced by an absolute width and height or the FILL_PARENT option)
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.leftMargin = 50; //Your X coordinate
params.topMargin = 60; //Your Y coordinate
之后的的LayoutParams添加到使用按钮:
button.setLayoutParams(params);
答
尝试使用
setTranslationX(float xVal)
公共浮动的getX()
在API级别11 这种观点的视觉x位置,以像素为单位。这相当于translationX属性加上当前的左侧属性。
返回 此视图的视觉x位置,以像素为单位。
+0
我想要在API级别10中执行此操作,api级别11是针对android 3.0的,而大多数android设备都具有三个较小的版本 – CristianCV 2013-04-24 09:36:27
如果你得到任何错误,只是贴上logcat的这里在你的问题 – umesh 2013-04-24 08:51:58
我没有错误什么的,只有当我从4.2.2更改为2.3.3 eclipse sais不能使用“button.setX”或“button.SetY()” – CristianCV 2013-04-24 09:17:35
这意味着这些方法不可用API级别10,意味着为Android 2.3.3 – umesh 2013-04-24 09:19:31