Android adjustResize 和 adjustPan 不起作用

时间:2021-01-16 15:59:17

标签: android coordinator-layout

我正在使用 CoordinatorLayout 和导航组件 NestedScrollView。我知道已经有很多关于这个问题的问题了,但目前我还没有找到解决方案。

我已经试过了:

  • 添加一个相对或 ConstraintLayout 作为根

  • android:fitsSystemWindows="true"(以及几乎所有
    的组合 它)

  • 删除
    app:layout_behavior="@string/appbar_scrolling_view_behavior"

清单:

 <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustPan">
 </activity>

xml(主活动):

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/CustomToolbar"
            app:titleTextColor="?attr/secondaryTextColor"
            app:layout_scrollFlags="scroll|enterAlways"/>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom"
        android:layout_gravity="bottom"
        android:background="@android:color/transparent"
        android:elevation="12dp">
    </androidx.coordinatorlayout.widget.CoordinatorLayout>
    

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        android:layout_gravity="bottom"
        app:menu="@menu/bottom_nav_menu"
        app:labelVisibilityMode="unlabeled" />

    <FrameLayout
        android:id="@+id/fragment_placeholder"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <fragment
            android:id="@+id/nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:defaultNavHost="true"
            app:navGraph="@navigation/mobile_navigation" />

    </FrameLayout>


    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_gravity="bottom|end"
        android:layout_marginBottom="68dp"
        android:backgroundTint="?attr/primaryDarkColor"
        app:borderWidth="0dp"
        app:rippleColor="?attr/accentColor"
        app:srcCompat="@drawable/ic_baseline_add_24_white" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

nav_host_fragment(NewMemoryFragment)的内容:

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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:id="@+id/scrollViewNewMemory"
    tools:context=".memories.NewMemoryFragment">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/textInputLayout3"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="24dp"
            android:layout_marginEnd="16dp"
            app:endIconMode="clear_text"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/constraintLayoutNewMemory"
            app:startIconDrawable="@drawable/ic_baseline_title_24">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/etMemoryTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/hint_title_newmemory" />
        </com.google.android.material.textfield.TextInputLayout>

0 个答案:

没有答案
相关问题