Gabriel Esteban
Gabriel Esteban

Reputation: 762

How to put up or down a view programatically?

I have a xml that the basic "skeleton" is

<RelativeLayout>
    <FrameLayout>
        <RelativeLayout>
            <TextView>
            </TextView>
            <TextView>
            </TextView>
        </RelativeLayout>
        <DrawView>
            //The view that changes 1
        </DrawVIew>
        <EditText>
            //The view that changes 2
        </EditText>
    </FrameLayout>
    <RelativeLayout>
    </RelativeLayout>
</RelativeLayout>

What I want is that using code the DrawView goes up or down, so sometimes you can use the DrawView and in other moments you can use the EditText, but ever the two views are showed.

How can I do that?

Upvotes: 0

Views: 109

Answers (2)

Twinsen
Twinsen

Reputation: 458

The only way to do this is to remove all of the FrameLayout's children and put them back in the order you need.

Or you can use another RelativeLayout and change the LayoutParams for the two Views

Upvotes: 0

ararog
ararog

Reputation: 1092

Since you are placing both widgets inside a FrameLayout you can change its gravity like below:

FrameLayout.LayoutParams drawViewLayoutParams = drawView.getLayoutParams();
drawViewLayoutParams.gravity = Gravity.BOTTOM;

FrameLayout.LayoutParams editTextLayoutParams = editText.getLayoutParams();
editTextLayoutParams.gravity = Gravity.TOP;

Upvotes: 1

Related Questions