Hello! Faced a problem. I create an application based on the Navigation Drawer Activity. When selecting an item from the left-pop-up menu (NavigationView), the container is displayed under the ToolBar. Thank you in advance for your help) 
activity_start.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout 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:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:openDrawer="start"> <include layout="@layout/toolbar" android:layout_width="match_parent" android:layout_height="match_parent" /> <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_start" app:menu="@menu/menu_main" /> </android.support.v4.widget.DrawerLayout> toolbar.xml
<?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" android:background="@android:color/holo_purple" tools:context="com.example.march.exider.MainActivity"> <include layout="@layout/content_main" /> <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> </android.support.design.widget.CoordinatorLayout> content_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="TextView" /> </RelativeLayout> Java code StartActivity
import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.design.widget.NavigationView; import android.support.v4.app.FragmentManager; 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.MenuItem; public class StartActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_start); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); 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(); } } @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. Fragment fragment = null; Class fragmentClass = null; int id = item.getItemId(); switch (id){ case R.id.test: fragmentClass = FirstFragment.class; break; } try { fragment = (Fragment) fragmentClass.newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction().replace(R.id.container, fragment).commit(); // Выделяем выбранный пункт меню в шторке item.setChecked(true); // Выводим выбранный пункт в заголовке setTitle(item.getTitle()); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } } Fragmenta class where recycleView is displayed
import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import java.util.ArrayList; public class FirstFragment extends Fragment { private RecyclerView mRecyclerView; private RecyclerAdapter mAdapter; private ArrayList<String> list = new ArrayList<>(); @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_first, container, false); mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); mRecyclerView.setHasFixedSize(true); // используем linear layout manager final LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(mLayoutManager); //наполнение массива list = getData(); // создаем адаптер mAdapter = new RecyclerAdapter(list); mRecyclerView.setAdapter(mAdapter); return view; } private ArrayList<String> getData() { for (int i = 0; i < 15; i++){ list.add(i, "item " + i); } return list; } } Fill adapter class
import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> { private ArrayList<String> mDataset; // класс view holder-а с помощью которого мы получаем ссылку на каждый элемент // отдельного пункта списка public static class ViewHolder extends RecyclerView.ViewHolder { public TextView mTextView; public ImageView mImageView; // ссылки на элементы в разметке карточки public ViewHolder(View v) { super(v); mTextView = (TextView) v.findViewById(R.id.tv_recycler_item); mImageView = (ImageView) v.findViewById(R.id.ig_recycler_item); } } // Конструктор public RecyclerAdapter(ArrayList<String> dataset) { mDataset = dataset; } // Создает новые views (вызывается layout manager-ом) @Override public RecyclerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // create a new view View v = LayoutInflater.from(parent.getContext()) .inflate(R.layout.recycler_item, parent, false); // тут можно программно менять атрибуты лэйаута (size, margins, paddings и др.) ViewHolder vh = new ViewHolder(v); return vh; } // Заменяет контент отдельного view (вызывается layout manager-ом) @Override public void onBindViewHolder(ViewHolder holder, int position) { holder.mTextView.setText(mDataset.get(position)); } // Возвращает размер данных (вызывается layout manager-ом) @Override public int getItemCount() { return mDataset.size(); } }
RecyclerViewapp:layout_behavior="@string/appbar_scrolling_view_behavior"- ahgpoug