2016-08-07 10 views
0

Ich habe Probleme beim Öffnen eines neuen Fragments, wenn ich auf eine Schaltfläche klicke. Das neue Fragment liegt über dem alten, wenn ich auf einen Button in den Einstellungen klicke. Ich habe ein paar Durchsuchungen durchgeführt, aber ich kann das anscheinend nicht beheben.Fehler beim Öffnen des neuen Fragments

Ein Bild und der entsprechende Code wird unten platziert. Jede Hilfe wäre willkommen.

enter image description here

Aktualisiert Bild (Fragment nicht richtig angezeigt): enter image description here

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle item selection 
    switch (item.getItemId()) { 
     case R.id.phase1: 
      Newsfeed1Fragment newFragment = new Newsfeed1Fragment(); 
      android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); 
      android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
      fragmentTransaction.replace(R.id.frame_content, newFragment); 
      fragmentTransaction.addToBackStack(String.valueOf(newFragment)); 
      fragmentTransaction.commit(); 
      break; 
     case R.id.phase2b: 
      Fragment newFragment1 = new NewsfeedFragment(); 
      android.support.v4.app.FragmentManager fragmentManager1 = getSupportFragmentManager(); 
      android.support.v4.app.FragmentTransaction fragmentTransaction1 = fragmentManager1.beginTransaction(); 
      fragmentTransaction1.replace(R.id.frame_content, newFragment1); 
      fragmentTransaction1.addToBackStack(String.valueOf(newFragment1)); 
      fragmentTransaction1.commit(); 
      break; 
     case R.id.phase2a: 
      Fragment newFragment2 = new Newsfeed2aFragment(); 
      android.support.v4.app.FragmentManager fragmentManager2 = getSupportFragmentManager(); 
      android.support.v4.app.FragmentTransaction fragmentTransaction2 = fragmentManager2.beginTransaction(); 
      fragmentTransaction2.replace(R.id.frame_content, newFragment2); 
      fragmentTransaction2.addToBackStack(String.valueOf(newFragment2)); 
      fragmentTransaction2.commit(); 
      break; 
     case R.id.phase3a: 
      Fragment newFragment3 = new Newsfeed3aFragment(); 
      android.support.v4.app.FragmentManager fragmentManager3 = getSupportFragmentManager(); 
      android.support.v4.app.FragmentTransaction fragmentTransaction3 = fragmentManager3.beginTransaction(); 
      fragmentTransaction3.replace(R.id.frame_content, newFragment3); 
      fragmentTransaction3.addToBackStack(String.valueOf(newFragment3)); 
      fragmentTransaction3.commit(); 
      break; 
     case R.id.phase3b: 
      Fragment newFragment4 = new Newsfeed3bFragment(); 
      android.support.v4.app.FragmentManager fragmentManager4 = getSupportFragmentManager(); 
      android.support.v4.app.FragmentTransaction fragmentTransaction4 = fragmentManager4.beginTransaction(); 
      fragmentTransaction4.replace(R.id.frame_content, newFragment4); 
      fragmentTransaction4.addToBackStack(String.valueOf(newFragment4)); 
      fragmentTransaction4.commit(); 
      break; 
     case R.id.phase4: 
      Fragment newFragment5 = new Newsfeed4Fragment(); 
      android.support.v4.app.FragmentManager fragmentManager5 = getSupportFragmentManager(); 
      android.support.v4.app.FragmentTransaction fragmentTransaction5 = fragmentManager5.beginTransaction(); 
      fragmentTransaction5.replace(R.id.frame_content, newFragment5); 
      fragmentTransaction5.addToBackStack(String.valueOf(newFragment5)); 
      fragmentTransaction5.commit(); 
      break; 

     default: 
      return super.onOptionsItemSelected(item); 
    } 
    return true; 
} 
} 

activity_newsfeed:

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

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 


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

<include layout="@layout/content_newsfeed" /> 

<com.aurelhubert.ahbottomnavigation.AHBottomNavigation 
    android:id="@+id/bottom_navigation" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" /> 

fragment_newsfeed:

<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: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="athena.sentineljs.com.athena.NewsfeedFragment" 
tools:showIn="@layout/activity_newsfeed" 
> 

<android.support.v4.widget.SwipeRefreshLayout 
android:id="@+id/swipeRefreshLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/rv" > 
</android.support.v7.widget.RecyclerView> 

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

+0

festgelegt Hintergrund für LinearLayout in Ihrem Fragment wird das Problem beheben. – Amir

+0

Danke dafür! Das Problem scheint jetzt gelöst zu sein, aber jetzt wird die erste Karte in meinem Fragment von der Werkzeugleiste abgeschnitten. Irgendwelche Gedanken dazu? Es soll wie folgt aussehen: https://photos.google.com/photo/AF1QipNXadI3hahP5fC35b5BHuhLBlBReYtbE6drMqtn –

+0

in dem Linearlayout folgende Zeile: ** App: layout_behavior = "@ Zeichenfolge/appbar_scrolling_view_behavior" ** – Amir

Antwort

1

FrameLayout haben standardmäßig keinen Hintergrund, so dass Sie einen Hintergrund definieren sollte. Auf diese Weise wird die vorherige fragment (oder die Ansicht hinter der aktuellen fragment) nicht mehr sichtbar.

für das zweite Problem, das Sie in den Kommentaren erwähnten, können Sie sich auf this Thema beziehen.