2017-02-02 2 views
2

si j'utilise parent mise en page .. fragment n'est pas visible et si j'utilise child layout comme conteneur .. son fragment d'affichage dans wrap_content, pas en plein écran .. même mon fragment hauteur mise en page est match_parentcomment afficher le fragment en plein écran

enter image description here

bien voulu me dire comment ouvrir un fragment en plein écran

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:id="@+id/container"> <!-- this id identifies fragment container --> 

    <LinearLayout 
     style="@style/innerContainer" 
     android:layout_margin="6dp" 
     android:background="@drawable/container"> 

    </LinearLayout> 

</LinearLayout> 

mise en page de fragment est

<LinearLayout 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" 
    android:orientation="vertical" 
    tools:context="com.example.thevisionspark.jobsite.AppliedUsers"> 

    <LinearLayout 
     style="@style/innerContainer"> 

     <TextView 
      style="@style/headings" 
      android:text="Applied Users" 
      android:layout_gravity="center_horizontal"/> 


    </LinearLayout> 


</LinearLayout> 

ce fragment est le code de chargement

FragmentTransaction fm = getSupportFragmentManager().beginTransaction(); 
        AppliedUsers frag = new AppliedUsers(); 
        frag.setArguments(bundle); 

        if(getSupportFragmentManager().getFragments() == null) 
         fm.add(R.id.container, frag).commit(); 

        else fm.replace(R.id.container, frag).commit(); 
+0

pouvez-vous ajouter un capture d'écran ? – yanivtwin

+0

aussi qu'est-ce que @ style/innerContainer? – yanivtwin

+0

@ style/innerContainer ce n'est que le style quel ensemble padding avec match_parent hauteur et largeur – Asad

Répondre

0

Suivez-le -

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

     <include 
      layout="@layout/layout_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <FrameLayout 
      android:id="@+id/flMain" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
     </FrameLayout> 

    </android.support.v4.widget.NestedScrollView> 

</LinearLayout> 

Sa mise en page principale. Ici FrameLayout avec l'ID flMain est le conteneur pour le fragment. Et le code suivant est pour le fragment -

public class CustomFragment extends Fragment { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
} 

@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    super.onCreateView(inflater, container, savedInstanceState); 

    View customeFragment = inflater.inflate(R.layout.layout_fragment, container, false); 


    return customeFragment; 
} 

}

et le code suivant est pour FragmentTransaction.

CustomeFragment customeFragment = new CustomeFragment(); 
     getFragmentManager().beginTransaction() .replace(R.id.flMain, customeFragment).addToBackStack(null).commit(); 

Si vous rencontrez un problème, alors mettez un commentaire ici.

+0

j'ai ajouté la capture d'écran gentiment le vérifie – Asad

+0

satisfait fournir le code complet de disposition de récipient. Je veux dire l'écran principal que vous avez joint en tant que capture d'écran. –

+0

Vous ne pouvez pas utiliser Activité et Fragment dans la même activité. Le fragment peut être utilisé comme une sous-activité de l'activité. Vous pouvez utiliser deux fragments dans une activité. Alors faites le fragment que vous avez marqué comme activité sur la capture d'écran ou utilisez CardView. –

0

Faites votre activité un FrameLayout

Le premier enfant restera le même avec la mise en page que vous voulez cacher plus tard,

Le deuxième enfant sera ceci:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:id="@+id/container"> <!-- this id identifies fragment container --> 
</LinearLayout> 

L'enfant intérieur de celui-ci (avec l'arrière-plan = "@ drawable/container") doit être défini à l'intérieur du fragment,

Essayez-le.

1

Vous pouvez utiliser un bouton pour lancer le fragment, à l'intérieur de l'écouteur de clic de ce bouton définir la visibilité des widgets de votre activité sur GONE comme ceci.

yourButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      yourWidget.setVisibility(View.GONE); 
      anotherWidget.setVisibility(View.GONE); 


      Fragment yourFragment = new YourFragment(); 
      FragmentManager fragmentManager = getFragmentManager(); 

      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
      fragmentTransaction.add(R.id.your_activity_layout, YourFragment); 
      fragmentTransaction.addToBackStack(null); 
      fragmentTransaction.commit(); 
     } 
    }); 

Créez maintenant une méthode abstraite dans une interface de rappel

public interface MakeVisible { 

void makeVisible(); 
} 

maintenant dans votre activité

public class Activity extends FragmentActivity implements MakeVisible{ 
@Override 
public void makeVisible() { 
    yourWidget.setVisibility(View.VISIBLE); 
    anotherWidget.setVisibility(View.VISIBLE); 


} 

enfin faire dans votre fragment

@Override 
public void onDetach() { 
    MakeVisible makeVisible = (MakeVisible) getActivity(); 
    makeVisible.makeVisible(); 
    super.onDetach(); 
}