问题描述
在我的活动有两种观点。两者都是在不同的父母。我有它们的坐标相对于所述屏幕。如何交换的两种观点的位置?
In my activity there are two views. Both are in different parents. I have their coordinates with respect to the screen. How to interchange the location of the two views?
推荐答案
您将需要调用父的ViewGroup方法 removeView()
这两个观点则 addView()
添加对方而是交换技术。
You will need to call the parent ViewGroup method removeView()
for both views then addView()
to add them back but swapper about.
所以,如果你的父母的意见被称为妈妈和爸爸,人们有一个孩子叫foo,那么其他的孩子叫吧:
So if your parent views are called mommy and daddy, one has a child called foo, the other a child called bar:
ViewGroup daddy = (ViewGroup)findViewById(R.id.daddy);
ViewGroup mommy = (ViewGroup)findViewById(R.id.mommy);
View foo = findViewById(R.id.foo);
View bar = findViewById(R.id.bar);
//detach children
daddy.removeView(foo);
mommy.removeView(bar);
//re-attach children
daddy.addView(bar);
mommy.addView(foo);
阅读有关removeView更多信息参考addView方法和看其他可用的方法。
Read the reference for ViewGroup for more information about the removeView and addView methods and to see other available methods.
这篇关于两种意见交换位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!