你如何交换 ViewGroup 中两个孩子的索引?
如何
setLeft
在子视图上使用?它似乎没有为 class 的对象定义View
。
编辑。
对#2 的回答setLeft
是只能从 API11 获得。同上setX
。
你如何交换 ViewGroup 中两个孩子的索引?
如何setLeft
在子视图上使用?它似乎没有为 class 的对象定义View
。
编辑。
对#2 的回答setLeft
是只能从 API11 获得。同上setX
。
I guess removing the views and re-inflating the layout is the only solution. Maybe you can try to use a ViewFlipper. I don't know if it's suitable for your case.
您可以删除所有子项,然后按要求的顺序添加。我没有找到另一种方式。
恕我直言,重组布局的最佳方法是使用 RelativeLayout。
当我这样做时:
// prepare rules
lpTopLeft = new RelativeLayout.LayoutParams(minDimension/5, minDimension/5);
lpTopLeft.setMargins(minDimension/50, minDimension/50, minDimension/50, minDimension/50);
lpTopLeft.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lpTopLeft.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
现在使用准备好的设置:
// rearrange child
bnReset.setLayoutParams(lpTopLeft);
最佳解决方案: Google 的 flexbox-layout
FexboxLayout 是一个库项目,它为 Android 带来了 CSS 灵活框布局模块的类似功能。
然后你可以设置
布局顺序
这个属性可以改变子视图的排列顺序。默认情况下,子项的显示和布局顺序与它们在布局 XML 中的显示顺序相同。如果未指定,则将 1 设置为默认值。