2016-12-25 4 views
0

Я не могу понять, почему основной фрагмент не показывает вкладки. Мой код не имеет никаких ошибок, его просто, когда я нажимаю элемент в навигационном ящике, не отображая фрагмент с вкладками. Может кто-то, пожалуйста, помогите, спасибо за ваше время, оцените его.ТАБЛИЦЫ Не отображаются в Фрагменте

Основной фрагмент кода

package app.com.navigatemenu; 

import android.content.Context; 
import android.net.Uri; 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentTabHost; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 


/** 
* A simple {@link Fragment} subclass. 
* Activities that contain this fragment must implement the 
* {@link MainFragment.OnFragmentInteractionListener} interface 
* to handle interaction events. 
* Use the {@link MainFragment#newInstance} factory method to 
* create an instance of this fragment. 
*/ 
public class MainFragment extends Fragment { 
    // TODO: Rename parameter arguments, choose names that match 
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER 
    private static final String ARG_PARAM1 = "param1"; 
    private static final String ARG_PARAM2 = "param2"; 
    private FragmentTabHost mTabHost; 


    // TODO: Rename and change types of parameters 
    private String mParam1; 
    private String mParam2; 

    private OnFragmentInteractionListener mListener; 

    public MainFragment() { 
     // Required empty public constructor 
    } 


    public static MainFragment newInstance(String param1, String param2) { 
     MainFragment fragment = new MainFragment(); 
     Bundle args = new Bundle(); 
     args.putString(ARG_PARAM1, param1); 
     args.putString(ARG_PARAM2, param2); 
     fragment.setArguments(args); 
     return fragment; 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     if (getArguments() != null) { 
      mParam1 = getArguments().getString(ARG_PARAM1); 
      mParam2 = getArguments().getString(ARG_PARAM2); 
     } 
    } 
/* 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     return inflater.inflate(R.layout.fragment_main, container, false); 
    } 
*/ 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 

     View rootView = inflater.inflate(R.layout.fragment_main,container, false); 


     mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost); 
     mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent); 

     mTabHost.addTab(mTabHost.newTabSpec("fragmentc").setIndicator("Fragment C"), 
       MovieFragment.class, null); 
     mTabHost.addTab(mTabHost.newTabSpec("fragmentb").setIndicator("Fragment B"), 
       GalleryFragment.class, null); 
     return rootView; 
    } 

    // TODO: Rename method, update argument and hook method into UI event 
    public void onButtonPressed(Uri uri) { 
     if (mListener != null) { 
      mListener.onFragmentInteraction(uri); 
     } 
    } 

    @Override 
    public void onAttach(Context context) { 
     super.onAttach(context); 
     if (context instanceof OnFragmentInteractionListener) { 
      mListener = (OnFragmentInteractionListener) context; 
     } else { 
      throw new RuntimeException(context.toString() 
        + " must implement OnFragmentInteractionListener"); 
     } 
    } 

    @Override 
    public void onDetach() { 
     super.onDetach(); 
     mListener = null; 
    } 

    public interface OnFragmentInteractionListener { 
     // TODO: Update argument type and name 
     void onFragmentInteraction(Uri uri); 
    } 
} 

Основная деятельность Код

package app.com.navact; 

import android.net.Uri; 
import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 
import android.view.View; 
import android.support.design.widget.NavigationView; 
import android.support.v4.view.GravityCompat; 
import android.support.v4.widget.DrawerLayout; 
import android.support.v7.app.ActionBarDrawerToggle; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.Menu; 
import android.view.MenuItem; 

public class MainActivity extends AppCompatActivity 
     implements NavigationView.OnNavigationItemSelectedListener, MainFragment.OnFragmentInteractionListener, 
     FragmentA.OnFragmentInteractionListener, FragmentB.OnFragmentInteractionListener { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     MainFragment fragment = new MainFragment(); 
     android.support.v4.app.FragmentTransaction fragmentTransaction = 
       getSupportFragmentManager().beginTransaction(); 
     fragmentTransaction.add(R.id.fragment_container, fragment); 
     fragmentTransaction.commit(); 

     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 



     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
         .setAction("Action", null).show(); 
      } 
     }); 

     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
       this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
     drawer.setDrawerListener(toggle); 
     toggle.syncState(); 

     NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
     navigationView.setNavigationItemSelectedListener(this); 
    } 

    @Override 
    public void onBackPressed() { 
     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     if (drawer.isDrawerOpen(GravityCompat.START)) { 
      drawer.closeDrawer(GravityCompat.START); 
     } else { 
      super.onBackPressed(); 
     } 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 

    @SuppressWarnings("StatementWithEmptyBody") 
    @Override 
    public boolean onNavigationItemSelected(MenuItem item) { 
     // Handle navigation view item clicks here. 
     int id = item.getItemId(); 

     if (id == R.id.nav_camera) { 
      MainFragment fragment = new MainFragment(); 
      android.support.v4.app.FragmentTransaction fragmentTransaction = 
        getSupportFragmentManager().beginTransaction(); 
      fragmentTransaction.add(R.id.fragment_container, fragment); 
      fragmentTransaction.commit(); 

      // Handle the camera action 
     } else if (id == R.id.nav_gallery) { 

     } else if (id == R.id.nav_slideshow) { 

     } else if (id == R.id.nav_manage) { 

     } else if (id == R.id.nav_share) { 

     } else if (id == R.id.nav_send) { 

     } 

     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     drawer.closeDrawer(GravityCompat.START); 
     return true; 
    } 

    @Override 
    public void onFragmentInteraction(Uri uri) { 

    } 
} 

Fragment_main раскладка

<android.support.v4.app.FragmentTabHost 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

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

      <FrameLayout 
       android:id="@+id/realtabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1"/> 

     </LinearLayout> 
    </android.support.v4.app.FragmentTabHost> 

Fragment_conatiner

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

</FrameLayout> 

Файл фрагмента контейнера

<?xml version="1.0" encoding="utf-8"?> 
<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" 
    tools:context="app.com.navact.MainActivity"> 

    <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> 


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

    </FrameLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     app:srcCompat="@android:drawable/ic_dialog_email" /> 

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

ответ

0

Изменение

<FrameLayout 
      android:id="@+id/realtabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"/> 

в

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

Пожалуйста, дайте мне знать результат.

+0

Он не работал ... – user7327850

0

ДО ТОГО, ЧТО ВЫ ЛЮБЫМ ИЗ ЭТОГО УБЕДИТЕСЬ, У ВАС ЕСТЬ РЕЗЕРВИРОВАНИЕ ВАШЕГО ПРОЕКТА, КАК Я НЕ ИСПЫТАЛ ЭТО !!!

ВНУТРИ COORDINATORLAYOUT Перед fragment_container Я хочу, чтобы вы разместите FrameLayout, убедитесь, что он layout_height является wrap_content. Я хочу, чтобы вы сделали это id, равное realtabcontent. Я хочу, чтобы добавить атрибут layout_weight к fragment_container и сделать его равным 1.

Я хочу, чтобы вы удалили основной фрагмент фрагмента, УБЕДИТЕСЬ, ЧТО У ВАС ЕСТЬ РЕЗЕРВНОЕ КОПИРОВАНИЕ ЭТОГО ПРОЕКТА !!!

ВНУТРИ MAINFRAGMENT

Я хочу, чтобы изменить onCreateView к:

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    mTabHost = new FragmentTabHost(getActivity()); 
    mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent); 
    mTabHost.addTab(mTabHost.newTabSpec("fragmentc").setIndicator("Fragment C"), MovieFragment.class, null); 
    mTabHost.addTab(mTabHost.newTabSpec("fragmentb").setIndicator("Fragment B"), GalleryFragment.class, null); 
    return inflater.inflate(R.id.fragment_container, null); 
} 
+0

Комментарии не для широкого обсуждения; этот разговор был [перемещен в чат] (http://chat.stackoverflow.com/rooms/131433/discussion-on-answer-by-blazedev-tabs-are-not-displayed-in-fragment). –

+0

я добавил это до fragment_container также добавил код в основном фрагменте для создания представления ... я запускал проект .... Я не вижу вкладок, но вижу текст на экране «Фрагмент галереи». .. выглядит как что-то работало, поскольку оно называлось фрагментом .... но никаких вкладок ... – user7327850

0

MainActivity

  package app.com.navact; 
      import android.net.Uri; 
      import android.os.Bundle; 
      import android.support.design.widget.FloatingActionButton; 
      import android.support.design.widget.Snackbar; 
      import android.view.View; 
      import android.support.design.widget.NavigationView; 
      import android.support.v4.view.GravityCompat; 
      import android.support.v4.widget.DrawerLayout; 
      import android.support.v7.app.ActionBarDrawerToggle; 
      import android.support.v7.app.AppCompatActivity; 
      import android.support.v7.widget.Toolbar; 
      import android.view.Menu; 
      import android.view.MenuItem; 

      public class MainActivity extends AppCompatActivity 
        implements NavigationView.OnNavigationItemSelectedListener, MainFragment.OnFragmentInteractionListener 
        { 

       @Override 
       protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 

        MainFragment fragment = new MainFragment(); 
        android.support.v4.app.FragmentTransaction fragmentTransaction = 
          getSupportFragmentManager().beginTransaction(); 
        fragmentTransaction.replace(R.id.fragment_container, fragment); 
        fragmentTransaction.commit(); 

        Toolbar toolbar = 

    (Toolbar) findViewById(R.id.toolbar); 
       setSupportActionBar(toolbar); 

       FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
       fab.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View view) { 
         Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
           .setAction("Action", null).show(); 
        } 
       }); 

       DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
       ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
         this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
       drawer.setDrawerListener(toggle); 
       toggle.syncState(); 

       NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
       navigationView.setNavigationItemSelectedListener(this); 
      } 

      @Override 
      public void onBackPressed() { 
       DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
       if (drawer.isDrawerOpen(GravityCompat.START)) { 
        drawer.closeDrawer(GravityCompat.START); 
       } else { 
        super.onBackPressed(); 
       } 
      } 

      @Override 
      public boolean onCreateOptionsMenu(Menu menu) { 
       // Inflate the menu; this adds items to the action bar if it is present. 
       getMenuInflater().inflate(R.menu.main, menu); 
       return true; 
      } 

      @Override 
      public boolean onOptionsItemSelected(MenuItem item) { 
       // Handle action bar item clicks here. The action bar will 
       // automatically handle clicks on the Home/Up button, so long 
       // as you specify a parent activity in AndroidManifest.xml. 
       int id = item.getItemId(); 

       //noinspection SimplifiableIfStatement 
       if (id == R.id.action_settings) { 
        return true; 
       } 

       return super.onOptionsItemSelected(item); 
      } 

      @SuppressWarnings("StatementWithEmptyBody") 
      @Override 
      public boolean onNavigationItemSelected(MenuItem item) { 
       // Handle navigation view item clicks here. 
       int id = item.getItemId(); 

       if (id == R.id.nav_camera) { 
        MainFragment fragment = new MainFragment(); 
        android.support.v4.app.FragmentTransaction fragmentTransaction = 
          getSupportFragmentManager().beginTransaction(); 
        fragmentTransaction.replace(R.id.fragment_container, fragment); 
        fragmentTransaction.commit(); 

        // Handle the camera action 
       } else if (id == R.id.nav_gallery) { 

       } else if (id == R.id.nav_slideshow) { 

       } else if (id == R.id.nav_manage) { 

       } else if (id == R.id.nav_share) { 

       } else if (id == R.id.nav_send) { 

       } 

       DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
       drawer.closeDrawer(GravityCompat.START); 
       return true; 
      } 

      @Override 
      public void onFragmentInteraction(Uri uri) { 

      } 
     } 

Главная Фрагмент

 package app.com.navact; 
     import android.app.LocalActivityManager; 
     import android.content.Context; 
     import android.content.Intent; 
     import android.net.Uri; 
     import android.os.Bundle; 
     import android.support.design.widget.TabLayout; 
     import android.support.v4.app.Fragment; 
     import android.support.v4.app.FragmentManager; 
     import android.support.v4.app.FragmentPagerAdapter; 
     import android.support.v4.app.FragmentTabHost; 
     import android.support.v4.view.ViewPager; 
     import android.view.LayoutInflater; 
     import android.view.View; 
     import android.view.ViewGroup; 


     /** 
     * A simple {@link Fragment} subclass. 
     * Activities that contain this fragment must implement the 
     * {@link MainFragment.OnFragmentInteractionListener} interface 
     * to handle interaction events. 
     * Use the {@link MainFragment#newInstance} factory method to 
     * create an instance of this fragment. 
     */ 
     public class MainFragment extends Fragment { 
      private static final String ARG_PARAM1 = "param1"; 
      private static final String ARG_PARAM2 = "param2"; 
      private String mParam1; 
      private String mParam2; 
      private FragmentTabHost mTabHost ; 

      private OnFragmentInteractionListener mListener; 
      public static TabLayout tabLayout; 
      public static ViewPager viewPager; 
      public static int int_items = 2 ; 

      public MainFragment() { 
       // Required empty public constructor 
      } 

      /** 
      * Use this factory method to create a new instance of 
      * this fragment using the provided parameters. 
      * 
      * @param param1 Parameter 1. 
      * @param param2 Parameter 2. 
      * @return A new instance of fragment MainFragment. 
      */ 
      // TODO: Rename and change types and number of parameters 
      public static MainFragment newInstance(String param1, String param2) { 
       MainFragment fragment = new MainFragment(); 
       Bundle args = new Bundle(); 
       args.putString(ARG_PARAM1, param1); 
       args.putString(ARG_PARAM2, param2); 
       fragment.setArguments(args); 
       return fragment; 
      } 

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

       if (getArguments() != null) { 
        mParam1 = getArguments().getString(ARG_PARAM1); 
        mParam2 = getArguments().getString(ARG_PARAM2); 
       } 
      } 

      @Override 
      public View onCreateView(LayoutInflater inflater, ViewGroup container, 
            Bundle savedInstanceState) { 

       View x = inflater.inflate(R.layout.tab_layout,null); 
       tabLayout = (TabLayout) x.findViewById(R.id.tabs); 
       viewPager = (ViewPager) x.findViewById(R.id.viewpager); 
       viewPager.setAdapter(new MyAdapter(getChildFragmentManager())); 

       tabLayout.post(new Runnable() { 
        @Override 
        public void run() { 
         tabLayout.setupWithViewPager(viewPager); 
        } 
       }); 

       return x; 
      } 

      // TODO: Rename method, update argument and hook method into UI event 
      public void onButtonPressed(Uri uri) { 
       if (mListener != null) { 
        mListener.onFragmentInteraction(uri); 
       } 
      } 

      @Override 
      public void onAttach(Context context) { 
       super.onAttach(context); 
       if (context instanceof OnFragmentInteractionListener) { 
        mListener = (OnFragmentInteractionListener) context; 
       } else { 
        throw new RuntimeException(context.toString() 
          + " must implement OnFragmentInteractionListener"); 
       } 
      } 

      class MyAdapter extends FragmentPagerAdapter { 

       public MyAdapter(FragmentManager fm) { 
        super(fm); 
       } 

       /** 
       * Return fragment with respect to Position . 
       */ 

       @Override 
       public Fragment getItem(int position) 
       { 
        switch (position){ 
         case 0 : return new TabFragment1(); 
         case 1 : return new TabFragment2(); 

        } 
        return null; 
       } 

       @Override 
       public int getCount() { 

        return int_items; 

       } 

       /** 
       * This method returns the title of the tab according to the position. 
       */ 

       @Override 
       public CharSequence getPageTitle(int position) { 

        switch (position){ 
         case 0 : 
          return "TabFragMent1"; 
         case 1 : 
          return "TabFragment2"; 

        } 
        return null; 
       } 
      } 


      @Override 
      public void onDetach() { 
       super.onDetach(); 
       mListener = null; 
      } 


      public interface OnFragmentInteractionListener { 
       // TODO: Update argument type and name 
       void onFragmentInteraction(Uri uri); 
      } 
     } 

Вкладка Макет

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:orientation="vertical" 
     android:layout_height="wrap_content"> 


     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:background="@android:color/holo_orange_dark" 
      app:tabIndicatorColor="@color/colorAccent" 
      app:tabSelectedTextColor="@android:color/holo_blue_bright" 
      app:tabTextColor="@color/colorPrimaryDark" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
     </android.support.design.widget.TabLayout> 


     <android.support.v4.view.ViewPager 
      android:id="@+id/viewpager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
     </android.support.v4.view.ViewPager> 



    </LinearLayout> 

Вкладка Activity1

 package app.com.navact; 

     import android.content.Context; 
     import android.net.Uri; 
     import android.os.Bundle; 
     import android.support.v4.app.Fragment; 
     import android.view.LayoutInflater; 
     import android.view.View; 
     import android.view.ViewGroup; 




     public class TabFragment1 extends Fragment { 
       @Override 
       public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
        return inflater.inflate(R.layout.fragment_tab_fragment1, container, false); 
       } 

     } 

TabActivity2

 package app.com.navact; 

     import android.content.Context; 
     import android.net.Uri; 
     import android.os.Bundle; 
     import android.support.v4.app.Fragment; 
     import android.view.LayoutInflater; 
     import android.view.View; 
     import android.view.ViewGroup; 


     public class TabFragment2 extends Fragment { 

      @Override 
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
       return inflater.inflate(R.layout.fragment_tab_fragment2, container, false); 
      } 
     } 

макет tab1

 <?xml version="1.0" encoding="utf-8"?> 
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="40dp" 
       android:textSize="30sp" 
       android:gravity="center" 
       android:id="@+id/textView" 
       android:layout_centerHorizontal="true" 
       android:textColor="@android:color/holo_blue_dark" 
       android:text="Primary\nFragment"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:autoLink="web" 
       android:textSize="15sp" 
       android:layout_marginTop="10dp" 
       android:layout_centerHorizontal="true" 
       android:text="androidbelieve.com" 
       android:textColor="#000" 
       android:layout_below="@+id/textView" 
       android:textStyle="italic"/> 

     </RelativeLayout> 

tab2Layout

 <?xml version="1.0" encoding="utf-8"?> 
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/textView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:text="Tab 2" 
       android:textAppearance="?android:attr/textAppearanceLarge"/> 

     </RelativeLayout> 

приложение построить Gradle

 apply plugin: 'com.android.application' 

     android { 
      compileSdkVersion 25 
      buildToolsVersion "25.0.1" 
      defaultConfig { 
       applicationId "app.com.navact" 
       minSdkVersion 19 
       targetSdkVersion 25 
       versionCode 1 
       versionName "1.0" 
       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
      } 
      buildTypes { 
       release { 
        minifyEnabled false 
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
       } 
      } 
     } 

     dependencies { 
      compile fileTree(dir: 'libs', include: ['*.jar']) 
      androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
       exclude group: 'com.android.support', module: 'support-annotations' 
      }) 
      compile 'com.android.support:appcompat-v7:25.1.0' 
      compile 'com.android.support:design:25.1.0' 
      compile 'com.android.support:support-v4:25.1.0' 
      testCompile 'junit:junit:4.12' 
      compile 'com.android.support:recyclerview-v7:25.1.0' 
     } 
+0

взял меня на 10 часов, чтобы добраться до этого решения, это скользящая вкладка внутри фрагмента, интегрированная с навигационным ящиком .... его 3am теперь, я сплю ... это мое возвращение к сообществу ... приветствия и веселые xmas .... :) – user7327850

+0

Пожалуйста, не просто сбрасывайте весь свой проект здесь - попробуйте объяснить это решение как [mcve] –