2

I have a lot of View in my Activity, and I want to make the View named imageView1 at the Background, the last one, exactly the inverse of imageView1.bringToFront();

Are there any method to call for this raison?

thank you.

  • 1
    Consider answers in [this](http://stackoverflow.com/questions/6759036/how-to-send-view-to-back-how-to-control-the-z-order-programmatically) question, maybe they will be helpfull for you – Denys Vasylenko Dec 06 '13 at 16:05

2 Answers2

0

I used a very interesting static function for this, because I searched before and I did not find any method

public static void bringToBack(final View v) {
    final ViewGroup parent = (ViewGroup)v.getParent();
    if (null != parent) {
        parent.removeView(v);
        parent.addView(v, 0);
    }
}
RiadSaadi
  • 391
  • 2
  • 7
  • 16
0
view.setOnTouchListener(new View.OnTouchListener){
    @Override
    public boolean onTouch (View v, MotionEvent event){
    if (event.getAction() == MotionEvent.ACTION_MOVE) {
        view.bringToFront()
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
        ViewGroup viewGroup = (ViewGroup) view.getParent();
        sendToBack(viewGroup, view);
    }
}
});


private static void sendToBack(ViewGroup viewGroup, View view) {
    if (viewGroup != null) {
        viewGroup.removeView(child);
        viewGroup.addView(child, 0);
    }
}