如何以百分比形式设置X和setY?

时间:2016-06-22 16:21:26

标签: android image position

我想动态定位图片。

setX和setY工作正常,但以像素为单位。 我希望我的应用程序可以升级到每个设备的屏幕。 此外,我希望它以横向模式工作。

什么是正确的方法?

1 个答案:

答案 0 :(得分:0)

setX和setY不是在Android中定位图片的正确方法。

您必须使用LinearLayout或RelativeLayout才能在任何方向和任何设备上支持设计。

可以动态创建和添加布局和ImageView。

LinearLayout linearLayout = (LinearLayout) findViewById(R.id.mylayout)
TextView txt1 = new TextView(MyClass.this);
linearLayout.setBackgroundColor(Color.TRANSPARENT);
linearLayout.addView(txt1);

感谢源代码作者:Deepak

您只需要为ImageView更改TextView。