如何在程序运行时更改布局参数
我有一个 ImageView 位于 FrameLayout 上。我希望能够通过设置边距来移动此 imageView:LayoutParams lp = new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
lp.setMargins(左, 上, 0, 0);
imageView.setLayoutParams(lp);
imageView.invalidate();
但是没有任何变化,我的 imageView 也没有移动。
我做错了什么?
设置新边距后,我是否需要执行除 imageView.invalidate()
之外的其他操作?
I have an ImageView sitting on a FrameLayout. I want to be able to move this imageView by setting a margin:LayoutParams lp = new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
lp.setMargins(left, top, 0, 0);
imageView.setLayoutParams(lp);
imageView.invalidate();
However nothing changes and my imageView does not move.
What am I doing wrong?
Do I need to be doing something different other than imageView.invalidate()
after I set new margins?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个,我想它会起作用
Try This ,I think it will work