Hi I'm little bit confused about BottomNavigationView
position behavior.
Why is enabling/disabling of scrollbars affecting resizing of layout and position of BottomNavigationView
?
I created simple example project to show my problem...
With this code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="sandbox.jarda.cz.bottomnavigationtest.MainActivity">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="test" />
</LinearLayout>
</ScrollView>
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="@menu/navigation" />
</LinearLayout>
Will the BottomNavigationView
stay under the Keyboard (when is opened)...
BUT :)
When I delete line/enable scroll bars
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
The main layout is "resized" and the BottomNavigationView
is on the top of the keyboard...
WHY?
Thx for answer:)
The reason is ScrollView. When you open keyboard, it resizes itself with available space excluding keyboard + height of bottom navigation view.
When Keyboard not showing it uses available height, excluding height of navigation view.
For more clarity, implement keyboard listener and there calculate height of scroll view. You can modify below code for that
Calling code. Can be into
onCreate
container.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener); // Here container is topmost LinearLayout in your layout
And
mOnGlobalLayoutListener
would be