2016-05-30 1 views
4

В моем проекте есть только одна панель инструментов, окруженная AppBarLayout, а также под ним расположен элемент управления NestedScrollView, который имеет макет CardView с линейной задержкой. нет проблема в том, что вложенные прокрутки перекрывать панель инструментов, как это я показать в образе enter image description hereВложенный scrollView не распознает панель инструментов

, а также в период выполнения его передать приложение, как нет инструментов, как это:

enter image description here

enter image description here

это мой код:

<?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/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbarLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     > 



<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/colorPrimary" 
    android:elevation="7dp" 
    app:theme="@style/ThemeOverlay.AppCompat" 
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" 

    android:titleTextColor="@color/colorPrimary" 
    app:layout_scrollFlags="scroll|enterAlways" 
    ></android.support.v7.widget.Toolbar> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.widget.NestedScrollView 

     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:nestedScrollingEnabled="true" 

     > 

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

      > 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
     </LinearLayout> 

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

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

экр oll_view_item код находится здесь:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="16dp" 
    android:elevation="5dp" 
    app:cardCornerRadius="5dp"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="15dp" 
    android:orientation="vertical" 

    > 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Dummy Header" 
     android:textColor="@android:color/holo_red_light" 
     android:textSize="20sp" 
     android:textStyle="bold" 
     /> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:text="@string/app_text" 
     /> 

</LinearLayout> 
</android.support.v7.widget.CardView> 
+0

Просто комментарий : 'app: theme' устарела на Панели инструментов. Используйте 'android: theme', он работает даже на нижней версии Android. – pdegand59

ответ

7

просто окружать код с LinearLayout, как это:

<?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/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     > 
    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbarLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     > 



<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/colorPrimary" 
    android:elevation="7dp" 
    app:theme="@style/ThemeOverlay.AppCompat" 
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" 

    android:titleTextColor="@color/colorPrimary" 
    app:layout_scrollFlags="scroll|enterAlways" 
    ></android.support.v7.widget.Toolbar> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.widget.NestedScrollView 

     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:nestedScrollingEnabled="true" 

     > 

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

      > 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
      <include layout="@layout/scroll_view_item" /> 
     </LinearLayout> 

    </android.support.v4.widget.NestedScrollView> 
    </LinearLayout> 
</android.support.design.widget.CoordinatorLayout> 
+0

Этот ответ помог мне. – Steve

3

Вы забыли указать поведение в ScrollView.

Добавить эту строку в NestedScrollView:

app:layout_behavior="@string/appbar_scrolling_view_behavior" 
1

Добавить ниже строку в NestedScrollView:

app:layout_behavior="@string/appbar_scrolling_view_behavior" 
Смежные вопросы