Search code examples
androidandroid-layoutandroid-fragmentsandroid-xmlbottomnavigationview

The height of bottomNaviagtionview become minimal in the some item while navigating


I have a bottomNavigationView in the MainActivity. When I click to second (SearchFragment) and last (AccountFragment) item,the height of bottomNavigationView become small and when again click on same menu item, the height of bottomNavigationView become normal.This happens only when I'm in home item(HomeFragment) and from there I navigate to second or last item.There isn't this problem in the third menu item (MyCourseFragment). Trouble Mode It is screenshot of normal state: Normal Mode This is layout of MainActivity:

    <android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <FrameLayout
        android:id="@+id/flContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="56dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:visibility="visible"/>
    </FrameLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_nav"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/bottom_nav_menu"
        app:itemBackground="@color/colorBackgroundNav"
        android:theme="@style/bottomNav"
        app:labelVisibilityMode="labeled"
        android:layout_gravity="bottom"
        />
</android.support.design.widget.CoordinatorLayout>

It is layout of MyCourseFragment:

     <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        tools:context=".view.MyCourseFragment">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin"
            android:background="@color/colorPrimary">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="دوره های من"
                android:layout_gravity="end"
                android:id="@+id/toolbar_title"
                android:layout_marginEnd="20dp"
                android:textColor="#fff"
                android:textStyle="bold"
                android:textSize="17sp"/>
        </android.support.v7.widget.Toolbar>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/courseRcy"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/toolbar"
            android:layout_marginTop="30dp"
            android:visibility="gone"/>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/categoryRcy"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/toolbar"
            android:layout_marginTop="30dp"/>
    </RelativeLayout>
It is layout of `SearchFragment`:

    <RelativeLayout 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"
    tools:context=".view.SearchFragment">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

    <SearchView
        android:id="@+id/searchbox"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_centerInParent="true"
        android:layout_margin="10dp"
        android:background="#FFF"></SearchView>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/CategoryRcy"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/searchbox"
        android:layout_marginTop="10dp" />

</RelativeLayout>

It is layout 'AccountFragment':

    <ScrollView android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

<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"
    tools:context=".view.AccountFragment">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:fitsSystemWindows="true"
        android:minHeight="?attr/actionBarSize"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="حساب کاربری"
            android:layout_gravity="end"
            android:id="@+id/toolbar_title"
            android:layout_marginEnd="20dp"
            android:textColor="#fff"
            android:textStyle="bold"
            android:textSize="17sp"/>
    </android.support.v7.widget.Toolbar>

    <android.support.v7.widget.CardView
        android:id="@+id/cardViewProfile"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        app:cardCornerRadius="15dp"
        android:layout_below="@+id/toolbar"
        android:visibility="gone">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ImageView
                android:id="@+id/imgAvatar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_avatar"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="20dp"/>
            <TextView
                android:id="@+id/txtName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="مریم کاظمی"
                android:layout_below="@id/imgAvatar"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                />
        </RelativeLayout>
    </android.support.v7.widget.CardView>
    <android.support.v7.widget.CardView
        android:id="@+id/cardViewInstructor"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/cardViewProfile"
        android:layout_marginTop="20dp"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        app:cardCornerRadius="15dp"
        android:padding="10dp"
        android:visibility="gone">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <TextView
            android:id="@+id/txtBeInstructor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="یک مدرس شو"
            android:layout_centerInParent="true"
            android:textColor="@color/colorPrimary"
            android:textStyle="bold"
            android:textSize="20sp"
            />
        </RelativeLayout>
    </android.support.v7.widget.CardView>
    <android.support.v7.widget.CardView
        android:id="@+id/cardViewSetting"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/cardViewInstructor"
        android:layout_marginTop="20dp"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        app:cardCornerRadius="15dp"
        android:visibility="gone">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <TextView
                android:id="@+id/txtPreferences"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="10dp"
                android:text="تنظیمات"/>
            <TextView
                android:id="@+id/txtLecturePlayBack"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="10dp"
                android:text="پخش دوره"
                android:layout_below="@+id/txtPreferences"/>
            <TextView
                android:id="@+id/txtContinueBackground"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="10dp"
                android:text="پخش پیوسته در بک گراند"
                android:layout_below="@+id/txtLecturePlayBack"/>
            <Switch
                android:id="@+id/switchCB"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/txtLecturePlayBack"
                android:layout_marginTop="10dp"
                android:layout_marginStart="20dp"/>
            <TextView
                android:id="@+id/txtDownloadOption"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="10dp"
                android:text="گزینه های دانلود ویدیو"
                android:layout_below="@+id/txtContinueBackground"/>
            <TextView
                android:id="@+id/txtDWiFi"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="10dp"
                android:text="دانلود فقط از طریق Wi-Fi"
                android:layout_below="@+id/txtDownloadOption"/>
            <Switch
                android:id="@+id/switchDWifi"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/txtDownloadOption"
                android:layout_marginTop="10dp"
                android:layout_marginStart="20dp"/>
            <TextView
                android:id="@+id/txtDSD"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="10dp"
                android:text="دانلود داخل کارت حافظه"
                android:layout_below="@+id/txtDWiFi"/>
            <Switch
                android:id="@+id/switchDSD"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/txtDWiFi"
                android:layout_marginTop="20dp"
                android:layout_marginStart="20dp"/>
            <TextView
                android:id="@+id/txtQualityVideo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="10dp"
                android:text="کیفیت دانلود ویدیو"
                android:layout_below="@+id/txtDSD"/>
            <TextView
                android:id="@+id/txtQuality"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtQualityVideo"
                android:layout_alignParentEnd="true"
                android:text="360p"
                android:layout_marginTop="5dp"
                android:layout_marginEnd="10dp"/>
            <TextView
                android:id="@+id/txtTitleEditNotf"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="10dp"
                android:text="تنظیمات نوتیفیکیشن"
                android:layout_below="@+id/txtQuality"/>
            <TextView
                android:id="@+id/txtEditNotf"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txtTitleEditNotf"
                android:layout_alignParentEnd="true"
                android:text="ویرایش تنظیمات نوتیفیکیشن ها"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginBottom="20dp"/>
        </RelativeLayout>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:id="@+id/cardViewPolicy"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        app:cardCornerRadius="15dp"
        android:layout_below="@+id/cardViewSetting"
        android:visibility="visible"
        android:layout_marginBottom="10dp">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <TextView
                android:id="@+id/txtShareApp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="پارس کلاس را به اشتراک بگذار"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="10dp"
                />
            <TextView
                android:id="@+id/txtPrivacy"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="مشاهده سیاست های حریم خصوصی"
                android:layout_below="@+id/txtShareApp"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="10dp"
                />
            <TextView
                android:id="@+id/txtTermOfUse"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="مقررات  استفاده"
                android:layout_below="@+id/txtPrivacy"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="10dp"
                />
            <TextView
                android:id="@+id/txtIntellectual"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="مشاهده سیاست مالکیت معنوی"
                android:layout_below="@+id/txtTermOfUse"
                android:layout_alignParentEnd="true"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="10dp"
                />
            <TextView
                android:id="@+id/txtSign"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ورود/ثبت نام"
                android:layout_below="@+id/txtIntellectual"
                android:layout_centerInParent="true"
                android:layout_marginTop="10dp"/>
            <TextView
                android:id="@+id/txtVersion"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="ParsClass v1.1"
                android:layout_below="@+id/txtSign"
                android:layout_centerInParent="true"
                android:layout_marginTop="10dp"
                android:paddingBottom="10dp"/>
        </RelativeLayout>
    </android.support.v7.widget.CardView>

</RelativeLayout>
</ScrollView>

Solution

  • Finally i find the solution.I just needed to add this line of code to onCreateView method of Account fragment.

    ((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);