Android: how to change layout_x, layout_y in an AbsoluteLayout dynamically?

笑着哭i 提交于 2019-12-01 06:51:44

Try this:

AbsoluteLayout.LayoutParams params = ((AbsoluteLayout.LayoutParams) test_image.getLayoutParams());
params.x = 100;
params.y = 100;
test_image.setLayoutParams(params); 

Absolute Layout is deprecated.

For this case, i would suggest to use FrameLayout.

One more thing, dp or dip is more preferrable other than px.

As android support multiple screen resolutions, its not good to mention fixed co-ordinates for a particular widget.

Ayaz Akbar

You must use Absolutelayout intead of relativelayout:

android:layout_x="100dp" not px

android:layout_y="100dp"

both used for absolutelayout.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!