如何在确定的位置膨胀视图?
我有一个带有“添加”和“删除”按钮的活动。
“添加按钮”会膨胀视图,“删除按钮”会删除选定的视图。
当我使用“添加按钮”膨胀视图时,它会自动绘制在任何先前膨胀的视图下方。
我想让用户能够上下移动每个膨胀视图,这样他就可以更改它们在屏幕中显示的顺序(以拖放效果)
+---------------------+ +---------------------+
| +-----------------+ | | +-----------------+ |
| | View 1 | | | | View 2 | |
| +-----------------+ | | +-----------------+ |
| | --> | |
| +-----------------+ | | +-----------------+ |
| | View 2 | | | | View 1 | |
| +-----------------+ | | +-----------------+ |
+---------------------+ +---------------------+
是否可以指定“位置”其中每个视图都膨胀了? (例如,在当前选定视图的下方或上方?)
如果不是,实现所需效果的最佳方法是什么?
(如果您认为有帮助,请随时询问任何代码)
I have an activity with an "Add" and a "Delete" button.
The "Add Button" inflates a view, the "Delete Button" removes a selected View.
When I inflate a view with the "Add Button", it is automatically drawn below any previously infalted view.
I would like to give the user the possibility to move each inflated view up and down, so he could change the order they are show in screen (in a drag'n'drop kind of effect)
+---------------------+ +---------------------+
| +-----------------+ | | +-----------------+ |
| | View 1 | | | | View 2 | |
| +-----------------+ | | +-----------------+ |
| | --> | |
| +-----------------+ | | +-----------------+ |
| | View 2 | | | | View 1 | |
| +-----------------+ | | +-----------------+ |
+---------------------+ +---------------------+
Is it possible to specify the "position" in which each view is inflated? (for instance, below or above the currently selected view?)
If not, what is the best way to accomplish the desired effect?
(feel free to ask for any piece of code, if you think it might help)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的视图看起来像一个垂直的
LinearLayout
。所以我建议你使用类似的东西:使用索引(你需要以某种方式确定)你可以控制位置。
LinearLayout
是ViewGroup的子类,因此该方法可用。文档:
[带索引的Viewgroup.addView][2]
[1]: http://developer.android. com/reference/android/view/LayoutInflater.html#inflate(int, android.view.ViewGroup)
[2]: http://developer.android .com/reference/android/view/ViewGroup.html#addView(android.view.View, int, android.view.ViewGroup.LayoutParams)
Your view looks like a vertical
LinearLayout
. So I would recommend you use something like:Using the INDEX (you need to determine somehow) you could control the position.
LinearLayout
is a child class of ViewGroup, so the method is available.Docs:
[Viewgroup.addView with index][2]
[1]: http://developer.android.com/reference/android/view/LayoutInflater.html#inflate(int, android.view.ViewGroup)
[2]: http://developer.android.com/reference/android/view/ViewGroup.html#addView(android.view.View, int, android.view.ViewGroup.LayoutParams)