FORUMS

How to set up a margin for navbar icon?

1 posts
Thanks Meter: 0
 
By Quabbelwabbel, Junior Member on 5th May 2020, 11:51 PM
Post Reply Email Thread
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 Code:
<item
    android:id="@+id/testid1"
    android:icon="@drawable/ic_test1"
    android:title="@string/Overview"
    android:state_pressed="true"
    />

The XML for the Navbar:

HTML Code:
<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.


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

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes