1

如何解決這個問題,使LinearLayout與系統按鈕相鄰或適合系統按鈕?將GridView替換爲RecycleView可以解決它嗎?目前我已經通過爲GridView適配器中的最後一個元素添加一些邊距來解決此問題,但我認爲應該有更好,更直接的方法。CoordinatorLayout中的視圖被系統按鈕重疊

preview

下面是代碼:

activity_main.xml中

<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    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.CoordinatorLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="@color/colorWhite" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      android:orientation="horizontal" 
      android:id="@+id/fragmnetLayout" 
      android:theme="@style/LayoutsStyle" > 

      <fragment 
       class="com.example.AlbumsFragment" 
       android:id="@+id/albumsFragment" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_margin="10dp"/> 

     </LinearLayout> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appBarLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <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/ThemeOverlay.AppCompat.Light" 
       app:layout_scrollFlags="scroll|enterAlways" /> 

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

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

    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:menu="@menu/drawer"/> 

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

fragment_albums.xml

<RelativeLayout 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" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 

<GridView 
    android:id="@+id/albumGridView" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:verticalSpacing="10dp" 
    android:horizontalSpacing="10dp" 
    android:stretchMode="columnWidth" 
    android:numColumns="2" 
    android:theme="@style/LayoutsStyle"/> 

</RelativeLayout> 

album_item.xml

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="left"> 

<com.example.SquareImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/albumImageView" /> 
</LinearLayout> 

回答

0

我終於找到了在這種情況下如何解決我的問題。 只需在工具欄的layout_scrollFlags中刪除「滾動」即可。像這樣:

<android.support.design.widget.AppBarLayout 
     android:id="@+id/appBarLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <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/ThemeOverlay.AppCompat.Light" 
      app:layout_scrollFlags="enterAlways" /> 

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