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)
Your view looks like a vertical LinearLayout
. So I would recommend you use something like:
View v = inflater.inflate(R.layout.XXXX, null);
yourLinearLayout.addView(v, INDEX, new LinearLayout.LayoutParams(...)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With