2

J'ai fait une mise en page 2 fragments pour l'écran de connexion et l'autre pour l'écran de registre et dans l'écran principal j'ai mis un fragment pour l'écran de connexion et un bouton si l'utilisateur veut enregistrer cliquez en ce bouton et le fragment de registre semble lui et le fragment de connexion disparaissent le problème est après que j'appuie sur le bouton d'enregistrement dans l'écran principal de l'écran de connexion apparaît derrière l'écran de registre est ici une photo pour elle login behind Register je ne sais pas quel est le problème ou je mal compris les fragments je ne sais pas voici la méthode onclick sur la classe MainActityFragments va l'un derrière l'autre

@Override 
         public void onClick(View view) { 
          String mytxt = inversebutton.getText().toString(); 
          Fragment fragmentSign = new Signin(); 
          Fragment fragmentregister = new Register(); 
          if(mytxt.equals("Register")){ // call signin frame 
           android.support.v4.app.FragmentManager fragmentManager= getSupportFragmentManager(); 
           fragmentManager.beginTransaction().replace(R.id.fragmentplace ,fragmentregister).commit(); 
           inversebutton.setText("SignIn"); 
          }else{ // call register fra 
           android.support.v4.app.FragmentManager fragmentManager= getSupportFragmentManager(); 
           fragmentManager.beginTransaction().replace(R.id.fragmentplace ,fragmentSign).commit(); 
           inversebutton.setText("Register"); 
          } 
         } 
        }); 

est ici le activitymain.xml

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/activity_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     tools:context="com.example.abdelmagied.myapplication.MainActivity" 
     android:background="#222"> 

     <fragment 
      android:layout_width="match_parent" 
      android:layout_height="300dp" 
      android:name="com.example.abdelmagied.myapplication.Signin" 
      android:id="@+id/fragmentplace" 
      android:layout_centerVertical="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <Button 
      android:text="Register" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/reverse" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:layout_marginTop="16dp" /> 

    </RelativeLayout> 

est ici la classe register_fragment

public class Register extends Fragment { 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    return inflater.inflate(R.layout.fragment_register, container, false); 
} 

est ici la classe fragment signin

public class Register extends Fragment { 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    return inflater.inflate(R.layout.fragment_register, container, false); 
} 

est ici le fragment_register.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context="com.example.abdelmagied.myapplication.Register" 
     android:background="#090" 
     android:id="@+id/registerfragment"> 

     <!-- TODO: Update blank fragment layout --> 

     <TextView 
      android:text="Name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_marginLeft="32dp" 
      android:layout_marginStart="32dp" 
      android:layout_marginTop="49dp" 
      android:id="@+id/textView" /> 

     <TextView 
      android:text="Password" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/textView" 
      android:layout_alignLeft="@+id/textView" 
      android:layout_alignStart="@+id/textView" 
      android:layout_marginTop="61dp" 
      android:id="@+id/textView3" /> 

     <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="textPersonName" 
      android:ems="10" 
      android:layout_alignParentTop="true" 
      android:layout_alignLeft="@+id/Rbutton" 
      android:layout_alignStart="@+id/Rbutton" 
      android:layout_marginTop="30dp" 
      android:id="@+id/registerN" /> 

     <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="textPassword" 
      android:ems="10" 
      android:layout_below="@+id/registerN" 
      android:layout_alignRight="@+id/registerN" 
      android:layout_alignEnd="@+id/registerN" 
      android:layout_marginTop="36dp" 
      android:id="@+id/Rpassword" /> 

     <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="textPassword" 
      android:ems="10" 
      android:id="@+id/RRpassword" 
      android:layout_alignBaseline="@+id/textView4" 
      android:layout_alignBottom="@+id/textView4" 
      android:layout_alignLeft="@+id/Rbutton" 
      android:layout_alignStart="@+id/Rbutton" /> 

     <Button 
      android:text="Register" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/Rbutton" 
      android:layout_below="@+id/textView4" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="57dp" /> 

     <TextView 
      android:text="Rpassword" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/textView4" 
      android:layout_centerVertical="true" 
      android:layout_alignLeft="@+id/textView3" 
      android:layout_alignStart="@+id/textView3" /> 
    </RelativeLayout> 

est ici le fragment_signin.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context="com.example.abdelmagied.myapplication.Signin" 
     android:background="#878" 
     android:id="@+id/signinfragment"> 

     <!-- TODO: Update blank fragment layout --> 

     <TextView 
      android:text="Name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="55dp" 
      android:layout_marginStart="55dp" 
      android:id="@+id/sn" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_marginTop="46dp" /> 

     <TextView 
      android:text="Password" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/sn" 
      android:layout_alignLeft="@+id/sn" 
      android:layout_alignStart="@+id/sn" 
      android:layout_marginTop="79dp" 
      android:id="@+id/textView2" /> 

     <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="textPersonName" 
      android:ems="10" 
      android:layout_above="@+id/textView2" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:id="@+id/sname" /> 

     <EditText 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="textPassword" 
      android:ems="10" 
      android:layout_alignBottom="@+id/textView2" 
      android:layout_alignLeft="@+id/sname" 
      android:layout_alignStart="@+id/sname" 
      android:id="@+id/signpassword" /> 

     <Button 
      android:text="SignIn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/Sbuton" 
      android:layout_below="@+id/signpassword" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="51dp" /> 
    </RelativeLayout> 
+0

simplement fournir votre fragment un fond vous serez bien – sumit

Répondre

0

Je pense que vous devriez utiliser DialogFragment qui sont ici pour ce genre de popups devant autres.

Vous pouvez l'utiliser comme ça

DialogFragment registerFragment = RegisterFragment.newInstance(0); 
registerFragment.show(getFragmentManager().beginTransaction(), "RegisterPopup"); 

Et votre fragment sera de classe DialogFragment. Habituellement, vous lancez un Dialog en commençant comme ça. Ensuite, selon ce que vous voulez, de nombreuses options sont possibles.

public class RegisterFragment extends DialogFragment { 
    ...   

    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     ... 
    } 
} 

Et vous pouvez trouver l'exemple sur le développeur Android DialogFragment

1

Plutôt que de prendre tag fragment en XML, il serait bon de prendre simplement une disposition en donnant son identifiant et de le remplacer par transaction fragment dynamique

Dans votre mise en page, changez-en prenant mise en page simple ou linéaire relative et doit donner ce contexte de mise en page, enlever cette étiquette de fragment et remplacer fragment par java de codage selon vous avez besoin

puis le remplacer au début de votre classe dans onCreate() méthode sous-> `

getSupportFragmentManager().beginTransaction().replace(R.id.fragmentplace, new Your_frag(), Constant.FragmentTags.fragmentTag).commit();