2

I am having so many views to in a relative layout which is able to zoom and rotate. what I am trying to achieve is, when I long click a view it should able to send that particular view to last . what I do is

   private void moveToBack(View currentView) {
        ViewGroup vg = ((ViewGroup) currentView.getParent());
        for (int i = 0; i < vg.getChildCount(); i++) {
            View v = vg.getChildAt(i);
            if (!v.equals(currentView)) {
                vg.bringChildToFront(v);
                break;
            }
        }
    }

This will set the another view above the selected view I need to send that particular view to last. MIn sdk is 17 and I can't change that.

Pravin Divraniya
  • 4,223
  • 2
  • 32
  • 49
DKV
  • 1,767
  • 3
  • 28
  • 49

1 Answers1

0

We don't have something like bringToback() method so only we could modify the order of childviews. I tried once to achieve it using tricky way :

 public void sendViewToBack(View child) {

        final ViewGroup mParent = (ViewGroup)child.getParent();
        if (null != mParent) {
          mParent.removeView(child);
          mParent.addView(child, 0);
      }
   }
Jai
  • 1,974
  • 2
  • 22
  • 42