0
ボタンをクリックしたときに新しいフラグメントを開く際に問題があります。新しいフラグメントは、設定のボタンをクリックすると、古いフラグメントの上にあります。私はいくつかの検索を行ってきましたが、これを修正することはできません。新しいフラグメントを開くときに問題が発生する
写真と関連コードが下に配置されています。どんな助けもありがとう。
@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>
フラグメント内のLinearLayoutの背景を設定すると問題が解決します。 – Amir
ありがとう!この問題は今のところ解決されているようだが、今では断片の最初のカードがツールバーで切り取られている。それについての考えは? これは次のようになります:https://photos.google.com/photo/AF1QipNXadI3hahP5fC35b5BHuhLBlBReYtbE6drMqtn –
LinearLayoutに次の行を追加してください:** app:layout_behavior = "@ string/appbar_scrolling_view_behavior" ** – Amir