Search code examples
androidlayoutscrollviewvisible

How to adapt layout size when a view is set visible/gone


I'm designing a login activity where i want EditText fields to appear below a button when this one is pressed. The thing is the bottom of my layout (which also is a button) is resized when EditTexts appear. I can't get it working with a global scrollview.

Any help would be highly appreciated :)

EDIT : here is the xml code, I skipped some buttons for the readers' sake. Basically when I programmatically display the editText fields, the last button called "linked" shrinks.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/tour_port_blurry"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/welcomeimage"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:contentDescription="@string/hello_world"
        android:paddingTop="10dp"
        android:src="@drawable/logo_welcome" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:gravity="center"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.2" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.6"
            android:animateLayoutChanges="true"
            android:gravity="center"
            android:orientation="vertical" >

            <Button
                android:id="@+id/buttonstore"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="17dip"
                android:background="@drawable/state_button_login_stouring"
                android:drawableLeft="@drawable/logostouring"
                android:gravity="left|center_vertical"
                android:paddingBottom="8dp"
                android:paddingLeft="12dp"
                android:paddingRight="8dp"
                android:paddingTop="8dp"
                android:textColor="#EEEEEE"
                android:textSize="14sp" />

            <EditText
                android:id="@+id/login_store"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="20dip"
                android:layout_marginTop="2dip"
                android:hint="adresse email"
                android:inputType="textEmailAddress"
                android:singleLine="true"
                android:textColor="#EEEEEE"
                android:textColorHint="#EEEEEE"
                android:color="#EEEEEE" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <EditText
                    android:id="@+id/mdp_store"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="20dip"
                    android:layout_marginTop="2dip"
                    android:layout_weight="0.8"
                    android:hint="mot de passe"
                    android:inputType="textPassword"
                    android:singleLine="true"
                    android:textColor="#EEEEEE"
                    android:textColorHint="#EEEEEE"
                    android:color="#EEEEEE" />

                <Button
                    android:id="@+id/buttonOk"
                    android:visibility="invisible"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.2"
                    android:background="@android:color/transparent"
                    android:textColor="#EEEEEE" />
            </LinearLayout>

            <Button
                android:id="@+id/buttonlinked"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/state_button_login_linkedin"
                android:drawableLeft="@drawable/logolinkedin"
                android:gravity="left|center_vertical"
                android:paddingBottom="8dp"
                android:paddingLeft="12dp"
                android:paddingRight="8dp"
                android:paddingTop="8dp"
                android:textColor="#EEEEEE"
                android:textSize="14sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.2" />
    </LinearLayout>
</LinearLayout>

</ScrollView>

Solution

  • Try setting the EditText visible property to 'invisible'(dont use gone) in XML and on the click of the button make it 'Visible'. THis wont gets other views change.