Android: Overlapping issue with multiple fragments under MainActivity containing Tabs -


i facing problem have 3 tabs inside mainactivity , each tab contains fragment. when click on item under drawer start new fragment, gets overlapped on mainactivity's tabs view. below code:

fragment currentfragment;      @nullable     @override     public view oncreateview(layoutinflater inflater, @nullable viewgroup container,                              @nullable bundle savedinstancestate) {          viewinflate = inflater.inflate(r.layout.fragment_city, container, false);          return viewinflate;     }      @override     public boolean onnavigationitemselected(menuitem item) {          // handle navigation view item clicks here.         intent i;         int id = item.getitemid();          if (id == r.id.nav_home) {             tablayout tl = (tablayout) findviewbyid(r.id.main_tabs);             tl.setvisibility(view.visible);             showfragment(new homefragment());             settitle(r.string.app_name);         }         if (id == r.id.nav_about_us) {             tablayout tl = (tablayout) findviewbyid(r.id.main_tabs);             tl.setvisibility(view.gone);             showfragment(new aboutusfragment());             settitle(r.string.about_us);         }         if (id == r.id.nav_favorites) {             tablayout tl = (tablayout) findviewbyid(r.id.main_tabs);             tl.setvisibility(view.gone);             showfragment(new favoritesfragment());             settitle(r.string.favorites);         }         if (id == r.id.nav_settings) {             = new intent(this, settingsactivity.class);             startactivity(i);         }          drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);         drawer.closedrawer(gravitycompat.start);         return true;     }      public void showfragment(fragment fragment) {          if (currentfragment != null && fragment.getclass().equals(currentfragment.getclass()))             return;          currentfragment = fragment;         fragmentmanager fragmentmanager = this.getsupportfragmentmanager();         if (fragmentmanager == null)             return;          fragmenttransaction ft = fragmentmanager.begintransaction();         if (ft == null)             return;          ft.replace(r.id.content_frame, fragment).commitallowingstateloss();     } 

below xml code of fragment_city.xml

<framelayout 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:background="@color/content_background"     tools:context="com.creationjunkies.fragments.cityfragment">      <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"         android:layout_width="match_parent"         android:layout_height="match_parent">          <android.support.v4.widget.swiperefreshlayout             android:id="@+id/swipe_refresh"             android:layout_width="match_parent"             android:layout_height="match_parent" >              <android.support.v7.widget.recyclerview                 android:id="@+id/citybargainsrecyclerview"                 android:scrollbars="vertical"                 android:layout_width="match_parent"                 android:layout_height="match_parent"/>         </android.support.v4.widget.swiperefreshlayout>     </relativelayout>  </framelayout> 

and activity_main.xml code is:

<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.drawerlayout     android:background="@color/content_background"     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/drawer_layout"     android:fitssystemwindows="true"     tools:opendrawer="start"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="com.creationjunkies.cities.mainactivity">      <android.support.design.widget.coordinatorlayout         xmlns:android="http://schemas.android.com/apk/res/android"         xmlns:app="http://schemas.android.com/apk/res-auto"         xmlns:tools="http://schemas.android.com/tools"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:fitssystemwindows="true">          <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"                 app:theme="@style/themeoverlay.appcompat.dark.actionbar"                 android:layout_width="match_parent"                 android:layout_height="?attr/actionbarsize"                 android:background="?attr/colorprimary"                 app:popuptheme="@style/apptheme.popupoverlay">              </android.support.v7.widget.toolbar>              <android.support.design.widget.tablayout                 android:id="@+id/main_tabs"                 android:layout_width="match_parent"                 android:layout_height="wrap_content" />          </android.support.design.widget.appbarlayout>           <linearlayout             xmlns:android="http://schemas.android.com/apk/res/android"             xmlns:app="http://schemas.android.com/apk/res-auto"             xmlns:tools="http://schemas.android.com/tools"             android:layout_width="match_parent"             android:layout_height="match_parent"             app:layout_behavior="android.support.design.widget.appbarlayout$scrollingviewbehavior"             android:orientation="vertical">              <framelayout                 android:id="@+id/frametopads"                 android:layout_width="match_parent"                 android:layout_height="wrap_content">             </framelayout>              <framelayout                 android:id="@+id/content_frame"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:layout_weight="1">                  <android.support.v4.view.viewpager                     android:id="@+id/tab_container"                     android:layout_width="match_parent"                     android:layout_height="match_parent"                     app:layout_behavior="android.support.design.widget.appbarlayout$scrollingviewbehavior" />              </framelayout>              <framelayout                 android:id="@+id/frameads"                 android:layout_width="match_parent"                 android:layout_height="wrap_content">             </framelayout>          </linearlayout>      </android.support.design.widget.coordinatorlayout>      <android.support.design.widget.navigationview         android:id="@+id/nav_view"         android:layout_width="wrap_content"         android:layout_height="match_parent"         android:layout_gravity="start"         android:fitssystemwindows="true"         app:headerlayout="@layout/nav_header_main"         app:menu="@menu/activity_main_drawer" />  </android.support.v4.widget.drawerlayout> 

your appreciated!

set fragment background white. solve issue.

<framelayout 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:background="#ffffff" tools:context="com.creationjunkies.fragments.cityfragment">  <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent">      <android.support.v4.widget.swiperefreshlayout         android:id="@+id/swipe_refresh"         android:layout_width="match_parent"         android:layout_height="match_parent" >          <android.support.v7.widget.recyclerview             android:id="@+id/citybargainsrecyclerview"             android:scrollbars="vertical"             android:layout_width="match_parent"             android:layout_height="match_parent"/>     </android.support.v4.widget.swiperefreshlayout> </relativelayout> 


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -