ZhangLei
ZhangLei

Reputation: 413

display a child view of frame layout at the front

I want to change the view layer of a FrameLayout, and I try to call bringToFront() method. It does not work. Then, I tried to setVisibility(View.GONE) and setVisibility(View.VISIBLE). Again, it does not work.

In fact, both of that method can change the top layer just once. For the second time, they all failed.

How can I do it?

private void next(){
    if(currentPage < MAX_INDEX){
        currentPage++;
        //indicator[currentPage].bringToFront();
        for(int i=0; i < MAX_INDEX; ++i){
            indicator[i].setVisibility(View.INVISIBLE);
        }
        Log.d("current page:", "current page = " + currentPage);
        indicator[currentPage].setVisibility(View.VISIBLE);
    } else {
        startActivity(new Intent(SetupActivity.this, MainActivity.class));
        SetupActivity.this.finish();
    }
}

NOTE: removeAllViews() and then addView() works for me. Anyone who d like to explain why I cant use bringToFront() and setVisibility() method, will be appreciated!

Upvotes: 0

Views: 2909

Answers (2)

TheOne_su
TheOne_su

Reputation: 747

after you have called bringToFront(),another two method: requestLayout() and invalidate() should be called on the view's parent to force the parent to redraw;

you can refer this below http://developer.android.com/reference/android/view/View.html#bringToFront()

Upvotes: 1

Anil kumar
Anil kumar

Reputation: 1534

then try this code...

private void next(){
    if(currentPage < MAX_INDEX){
        currentPage++;
        //indicator[currentPage].bringToFront();

        framelayout.removeAllViews();

        Log.d("current page:", "current page = " + currentPage);
        framelayout.addView(indicator[currentPage]);
    } else {
        startActivity(new Intent(SetupActivity.this, MainActivity.class));
        SetupActivity.this.finish();
    }
}

Upvotes: 2

Related Questions