How to set up a margin for navbar icon?

Search This thread

Quabbelwabbel

New member
Mar 22, 2017
1
0
I am using BottomNavigationview and I want to animate the height of it, so it is extendable. My problem is that the Items stay centered vertically, but they should have a fix top-margin of e.g. 5dp. How is it possible to move them up with the top of the navbar?


My XML for one of five Items (with text!) (in menu folder):

HTML:
<item
    android:id="@+id/testid1"
    android:icon="@drawable/ic_test1"
    android:title="@string/Overview"
    android:state_pressed="true"
    />


The XML for the Navbar:

HTML:
<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:layout_gravity="bottom"
    android:background="@color/white"
    app:elevation="0dp"
    app:itemIconSize="26dp"
    app:itemIconTint="@color/NavBarGrey"
    app:itemRippleColor="#B5F1F1F1"
    app:itemTextColor="@color/NavBarGrey"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:menu="@menu/bottom_nav_menu" />


Here the Kotlin-Code for the "up" animation:

Code:
val anim = ValueAnimator.ofInt(convertDpToPixel(56.0).toInt(), convertDpToPixel(400.0).toInt())
anim.addUpdateListener { valueAnimator ->
    val `val` = valueAnimator.animatedValue as Int
        val layoutParams: ViewGroup.LayoutParams =
                bottom_navigation.getLayoutParams()
        layoutParams.height = `val`
        bottom_navigation.setLayoutParams(layoutParams)
}
anim.setInterpolator(OvershootInterpolator(1.0f))
anim.duration = 450
anim.start()


Here is how it looks right now.
a3bXC.gif


The round items should move up to the top like the blue button (which is an extra object and not part of the navbar)