Android 添加到Layout后修改ImageView参数
Android modify ImageView parameters after adding to Layout
如果我有 ImageView
foo
我可以在将其添加到布局之前修改其参数:
RelativeLayout.LayoutParams testParams = new RelativeLayout.LayoutParams(500,500);
foo.setLayoutParams(testParams);
然后我将 foo
添加到布局中:
exampleLayout.addView(foo);
在布局中添加foo
后如何修改参数? (我读到如果 foo
已经添加到布局中,则有一个不同的过程)
添加 foo 后您仍然可以编辑。
在你的 foo 上添加运行时的 id。让我们说。 foo.setId(23);
现在在运行时 examplelayout.findviewbyid(23)
会给你你的观点。
现在你可以更新参数了。并调用 invalidate()
尝试在添加到它的parent之前修改布局参数,但是如果你想修改它,首先通过它的ID找到它,然后使用getLayoutParams()
方法修改它,然后使用[=重新设置它11=].
如果我有 ImageView
foo
我可以在将其添加到布局之前修改其参数:
RelativeLayout.LayoutParams testParams = new RelativeLayout.LayoutParams(500,500);
foo.setLayoutParams(testParams);
然后我将 foo
添加到布局中:
exampleLayout.addView(foo);
在布局中添加foo
后如何修改参数? (我读到如果 foo
已经添加到布局中,则有一个不同的过程)
添加 foo 后您仍然可以编辑。
在你的 foo 上添加运行时的 id。让我们说。 foo.setId(23);
现在在运行时 examplelayout.findviewbyid(23)
会给你你的观点。
现在你可以更新参数了。并调用 invalidate()
尝试在添加到它的parent之前修改布局参数,但是如果你想修改它,首先通过它的ID找到它,然后使用getLayoutParams()
方法修改它,然后使用[=重新设置它11=].