I have a linear vertical layout as below. I need in my application to switch the Button and the TextView. To hide button and show text then change etc. If I use setVisibility(View.INVISIBLE) for the button it disappears from the screen but it still hold the place. How can I switch those elements without remove them completely?
<Chronometer
android:id="@+id/chronometer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:textSize="30sp"
android:text="Chronometer" />
<Button
android:id="@+id/stopButton"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/stop_button" />
<TextView
android:id="@+id/wrongCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:textSize="30sp"
android:text="" />
use-
button.setVisibility(View.GONE);
Suppose your created button is as follows...
Button button = (Button) findViewById(R.id.stopButton);
When you want to hide that Button write this...
button.setVisibility(View.GONE);
And when you want to show that button again then write...
button.setVisibility(View.VISIBLE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With