Mes
Mes

Reputation: 1691

Switch between two layouts at runtime

I have a layout which is mainly a linearlayout with a Button and another layout which is is a linearlayout again with an EditText and two buttons : Cancel and Submit.

What I want is initially the first layout to be displayed. When user clicks the button this layout is being replaced by the 2nd layout(the one with the two buttons).

I have already tried ViewFlipper but the problem is that it takes the height of the one with bigger height. So when first layout is displayed it has a big white space between the button and the content below it.

Upvotes: 0

Views: 263

Answers (3)

Marcin Koziński
Marcin Koziński

Reputation: 11074

If you want to keep using a ViewFlipper you can fix the height issue by adding this to your ViewFlipper in XML:

android:measureAllChildren="false"

Upvotes: 1

Robinhiio
Robinhiio

Reputation: 105

Layout1.setVisibility(INVISIBLE) Layout2.setVisibility(VISIBLE)

Upvotes: 1

Icero
Icero

Reputation: 81

Try use only one layout and set VISIBLE or GONE:

View b = findViewById(R.id.button);
b.setVisibility(View.GONE);

Or If you Have two layouts, use Intent:

Intent i = new Intent(this, ActivityTwo.class);
startActivity(i)

Upvotes: 0

Related Questions