Is it possible to make items in a ListView have different z-position/index?
I want one item in my ListView to always be on top of other views in my layout.
See my illustration here:
The red bar is another view outside the ListView (in my case a vertical seekbar).
I have tried calling View.bringToFront()
on a certain item but that didn't work at all.
Any ideas?
Here is how I would go about achieving the effect you desire:
Each item in the list should have a red bar in it that is the height of the item. That way all the red bars line up making it look like there is just one red bar when in fact there is one per item.
If you are using a FrameLayout
, the order of the children determines the drawing order, for example the 3rd child of a FrameLayout
will appear on top of the 1st and 2nd child.
Then at runtime you can arrange the red bar above or below the contents of a each item. In the bindView
method of your adapter you can use the bringToFront
method to bring the red bar to the front for that view. Don't forget that views are recycled in the ListView
so you will need to move the red bar to correct z position every time.
Here are is a very stripped down example XML file for an item in the view, let me know if you need more information.
item_red_bar_bottom.xml:
<FrameLayout ...>
<ImageView .../> <!-- Red bar on bottom -->
<FrameLayout ...>
<!-- Normal item contents go here -->
</FrameLayout>
</FrameLayout>
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