How to rebuild the XML of a Fragment layout when it is expanded?

Asked

Viewed 65 times

1

I have a screen with a Fragment, that without being expanded, it just shows the user and password field and the sign up button, and I wanted that when I expanded it, fields like name, date of birth, municipality, state, were inserted between the password field and the sign up button, remembering that it expands when the user is included in the user field.

XML from Fragment ta thus:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView android:id="@+id/login_form" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout android:id="@+id/email_novo_form" android:layout_width="match_parent"
        android:layout_height="wrap_content" android:orientation="vertical">

        <android.support.design.widget.TextInputLayout android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText android:id="@+id/campoEmailNovoUsuario" android:layout_width="match_parent"
                android:layout_height="wrap_content" android:hint="@string/prompt_email"
                android:inputType="textEmailAddress" android:maxLines="1"
                android:singleLine="true" />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content" android:hint="@string/prompt_password"
                android:imeActionId="@+id/login"
                android:imeActionLabel="@string/action_sign_in_short"
                android:imeOptions="actionUnspecified" android:inputType="textPassword"
                android:maxLines="1" android:singleLine="true"
                android:id="@+id/campoSenhaNovo" />

        </android.support.design.widget.TextInputLayout>

        <CheckBox
            android:id="@+id/chk_mostrar_senha"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/chk_mostrar_senha"/>

        <TextView
            android:id="@+id/texto_termos_criar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:textAlignment="center"/>

        <Button android:id="@+id/email_criar_button" style="?android:textAppearanceSmall"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_marginTop="5dp" android:text="@string/acao_nova_conta"
            android:textStyle="bold"
            android:textColor="@color/branco"
            android:background="@drawable/botao_arredondado"
            android:gravity="center_horizontal|center_vertical"
            android:layout_gravity="center_horizontal" />

    </LinearLayout>
</ScrollView>

that’s all

1 answer

1


In the layout of Activity add a Framelayout wherever the content of Fragment:

.....
.....
<FrameLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/fragment_placeholder">
</FrameLayout>  
.....
.....

When you want to "expand" the Fragment execute the following code:

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.fragment_placeholder, new Sua_Classe_Fragment());
    ft.commit();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.