底部导航,在切换位置后临时出屏

时间:2018-04-27 14:00:26

标签: java android kotlin material-design bottomnavigationview

我尝试使用底部导航。动作和设计运作良好,但有时随机,我的底部导航从屏幕上退下几秒钟,然后在没有任何动作的情况下正常返回。

这是我的xml文件,底部导航和框架布局(包含片段)

<?xml version="1.0" encoding="utf-8"?>
<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.support.constraint.ConstraintLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".Activities.MainActivity">

    <FrameLayout
        android:id="@+id/frame_layout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/bottom_bar_navigation"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_bar_navigation"
        style="@style/BottomNavigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottombar_tabs" />


</android.support.constraint.ConstraintLayout>

当我切换片段时:

...

bottomBar?.setOnNavigationItemSelectedListener {
        when (getTabInfo(it.itemId)) {
            xx.TAB_MESSENGER -> onFragmentInteraction(
                    MessengerFragment(),
                    tab_Bar_Object.TAB_MESSENGER
            )
            xx.TAB_GUARD -> onFragmentInteraction(
                    MyGuardsFragment(),
                    tab_Bar_Object.TAB_GUARD
            )
            xx.TAB_SEARCH -> onFragmentInteraction(
                    SearchFragment(),
                    tab_Bar_Object.TAB_SEARCH
            )
            xx.TAB_KNOWN -> onFragmentInteraction(
                    KnownApplicantsListFragment(),
                    tab_Bar_Object.TAB_KNOWN
            )
            xx.TAB_ACCOUNT -> onFragmentInteraction(
                    UserAccountFragment(),
                    tab_Bar_Object.TAB_ACCOUNT
            )
        }

    }

...

private fun onFragmentInteraction(fragment: Fragment, tabBarObject: xx): Boolean {
    if (selectedTab != tabBarObject.position) {
        selectedTab = tabBarObject.position
        val fragmentTransaction = supportFragmentManager.beginTransaction()
        fragmentTransaction.setCustomAnimations(R.anim.fade_in, R.anim.fade_out)
        fragmentTransaction.replace(R.id.frame_layout, fragment, tabBarObject.tabName)
        fragmentTransaction.commit()
        return true
    }
    return false
}

What it should do

My problem

问题只出现在&#34; Guard&#34;片段,有时是&#34;已知&#34;分段。 这些照片出现在&#34; Guard&#34;片段。

1 个答案:

答案 0 :(得分:0)

你能提供完整的布局xml吗?没有它,它只是在猜测。一种可能的解决方案是将android:layout_height="wrap_content"替换为维度值,等于128dp或最适合您的维度。