3

Я пытаюсь обновить свое приложение, создав поведение Material Design. До сих пор мое приложение не имеют навигационный ящик и MainActivity, который загружает фрагмент желания на основе элемента мыши в меню ящика (следующим образом :)Свертывание панели инструментов с использованием той же панели инструментов на разных фрагментах в зависимости от поведения

enter image description here

При нажатии на «Consejos» это заменить фрагмент с содержанием желания следующим

MainActivity

private void selectItem(String title, int id) { 
     Bundle args = new Bundle(); 
     args.putString(PlaceholderFragment.ARG_SECTION_TITLE, title); 

     Fragment fragment = PlaceholderFragment.newInstance(title); 
     fragment.setArguments(args); 
     FragmentManager fragmentManager = getSupportFragmentManager(); 
     fragmentManager 
       .beginTransaction() 
       .replace(R.id.main_content, fragment) 
       .commit(); 


     switch (id) { 
      case R.id.nav_localizacion: 
       //Snackbar.make(mSnackBarView, R.string.menu_localization, Snackbar.LENGTH_SHORT).show(); 
       mCurrentSelectedPosition = 0; 
       LocalizacionFragment fragment_localizacion = new LocalizacionFragment(); 
//    fragmentManager = getSupportFragmentManager(); 
//    Snackbar.make(mSnackBarView, R.string.menu_localization, Snackbar.LENGTH_SHORT).show(); 
       fragmentManager 
         .beginTransaction() 
         .replace(R.id.main_content, fragment_localizacion) 
         .commit(); 
       break; 
      case R.id.nav_productos: 
       Snackbar.make(mSnackBarView, R.string.menu_productos, Snackbar.LENGTH_SHORT).show(); 
       mCurrentSelectedPosition = 1; 
       fragmentManager 
         .beginTransaction() 
         .replace(R.id.main_content, fragment) 
         .commit(); 
       break; 
      case R.id.nav_consejos: 
       Snackbar.make(mSnackBarView, R.string.menu_consejos, Snackbar.LENGTH_SHORT).show(); 
       mCurrentSelectedPosition = 3; 
       ConsejosFragment fragment_consejo = new ConsejosFragment(); 
//    final Fragment fragment_consejo = new ConsejosFragment(); 
       fragmentManager 
         .beginTransaction() 
         .replace(R.id.main_content, fragment_consejo) 
         .commit(); 
//    getSupportFragmentManager().beginTransaction().add(R.id.main_content, fragment_consejo).commit(); 
       break; 
      default: 
       break; 
     } 


     drawerLayout.closeDrawers(); // Cerrar drawer 

     setTitle(title); // título actual 

    } 

Он открывает это:

enter image description here

Затем, если вы нажмете на «Recetas» снова заменяет фрагмент с содержанием желания:

enter image description here

Но вот вещь, если вы нажмете на элемент Я хочу, чтобы открыть еще один фрагмент и используйте AppBarLayout вместе с CollapsingToolbarLayout, чтобы показать изображение с рецептом.

Это расположение описания содержания рецепт:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_content_recetas" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

<android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/detail_backdrop_height" 
     android:fitsSystemWindows="true" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <ImageView 
       android:id="@+id/backdrop" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true" 
       android:scaleType="centerCrop" 
       android:src="@drawable/redono_ternera_mechado" 
       app:layout_collapseMode="parallax" /> 


      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar_view" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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

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

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

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

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

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

     </LinearLayout> 

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

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

Это код RecipeDescription Фрагмент

public class RecetaViewFragment extends Fragment { 

    private Context context; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     /* Inflamos el layout */ 
     View v = inflater.inflate(R.layout.recetas_descripcion_layout, container, false); 
     ImageView imageView = (ImageView) v.findViewById(R.id.backdrop); 
     Picasso.with(context).load(R.drawable.sopa_goulash_ternera).into(imageView); 

     Toolbar toolbar = (Toolbar) v.findViewById(R.id.toolbar_view); 
     ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); 
     if (toolbar != null) { 
      toolbar.setSubtitle("Descripción"); 
     } 
     context = v.getContext(); 
     return v; 
    } 

Но это то, что случилось при запуске приложения:

enter image description here

enter image description here

У этого есть панель сворачивания, встроенная в оригинальную панель инструментов, мой вопрос в том, что мой подход - неправильный подход. Я имею в виду, что у меня должна быть только одна панель инструментов, а затем применена или нет рушится, нужна ли мне это или нет, или мне нужно найти способ скрыть исходную панель инструментов и использовать ее (но что происходит, когда я хочу дать собственно назад навигация в мое приложение?)

Спасибо, пожалуйста, спросите меня для больше кода, если нужно это

ответ

0

в моем случае я с подобной проблемой.

МОЙ СЛУЧАЙ:

Я хочу, чтобы панель инструментов в деятельности, так как у меня есть панель навигации, но и хотят использовать Сворачивание панели инструментов в фрагменте.

Я только что сделал одно изменение, которым я доволен.

В Fragment панели я добавил это:

android:layout_height="0dp"