【问题标题】:Views inside CoordinatorLayout are overlapped by system buttonsCoordinatorLayout 中的视图被系统按钮重叠
【发布时间】:2016-06-15 09:50:57
【问题描述】:

如何解决这个问题,使 LinearLayout 与系统按钮相邻或适合?将 GridView 替换为 RecycleView 可以解决吗?目前我已经通过为 GridView 适配器中的最后一个元素添加一些边距来解决这个问题,但我认为应该有更好、更直接的方法。

代码如下:

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>

【问题讨论】:

    标签: android xml android-layout material-design android-support-library


    【解决方案1】:

    我终于找到了如何在这种特殊情况下解决我的问题。 只需在工具栏的 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>
    

    【讨论】:

      猜你喜欢
      • 2016-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-06
      • 1970-01-01
      • 2021-12-26
      • 2023-02-26
      相关资源
      最近更新 更多