Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bring a view to front without calling bringToFront()?

There is apparently a bug in Android which breaks View.bringToFront.

If I have Views arranged in a GridView and want to bring a View to front by calling bringToFront(), it may get moved to the bottom right position in the GridView.

Something shady is going on there, so I can't use bringToFront(). When I don't call it, everything works fine. But the Views overlap - if I use scale animation to scale up a View, it's partially obscured by the Views to the bottom and to the right.

I've checked out bringToFront's source and it calls parent.bringChildToFront(...)

it's this method

public void bringChildToFront(View child) {
     int index = indexOfChild(child);
      if (index >= 0) {
          removeFromArray(index);
          addInArray(child, mChildrenCount);
          child.mParent = this;
      }
  }

it apparently removes the View from itself! Without mercy! Is a ViewGroup so dumb that it can't manage Z-indexes in any other way that shuffling controls around? Obviously when GridView removes its child and then adds it back again, it gets placed at the end of the Grid!

Is there anything I can do to show a View on top of others without resorting to some hacking? One thing that comes to my mind is to create another View above the GridView, which will appear to be above the one I'm trying to bringToFront(), but I don't like this solution.

like image 605
Axarydax Avatar asked Dec 08 '10 20:12

Axarydax


1 Answers

apparently I missed the android:clipChildren="false" property in GridView. It solves my problem.

like image 191
Axarydax Avatar answered Oct 13 '22 22:10

Axarydax