Anbarasu Chinna
Anbarasu Chinna

Reputation: 1005

How to create vertical BottomNavigationView android?

I have an activity that have 4 fragment on top and BottomNavigationView with 4 items on bottom. It is working fine in mobile devices. When i go for tablet with LANDASCAPE i want to move that BottomNavigationView to left of the activity with vertical orientation like below.

Is this achievable using BottomNavigationView or should I go for NavigationMenu android.

enter image description here

Upvotes: 12

Views: 6109

Answers (5)

Ajay Venugopal
Ajay Venugopal

Reputation: 1710

You cant move the BottomNavigationView to left area of the layout.

BottomNavigationView does not meet tablet material design specification

The only way is You need to check the screen orientation on the start like

if (islandcape()){

//Create the Navigation view layout here.. 

}else{

//Create the BottomNavigationView layout here .. 

}

Note: You need to write a function to check the orientation and replace the islandcape() in the above code

Also try the bellow library that will do the job neatly.

Iiro Krankka https://github.com/roughike/BottomBar

enter image description here

Upvotes: 0

user9449244
user9449244

Reputation:

   <item 
    android:id="@+id/text"
    android:title="@string/about"
    android:icon="@android:drawable/ic_menu_info_details"
    app:showAsAction="never"/>

Put app:showAsAction="never" in evey menu item and try...

Upvotes: 0

Vanshaj Daga
Vanshaj Daga

Reputation: 2165

Well i managed to do it, what you want with BottomNavigationView, by some tweaking in orientation change and moving some views. Firstly for tap into orientation change i added this to Activity tag in AndroidManifest

android:configChanges="orientation|screenSize"

and in my Activity i added following

 @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
            BottomNavigationView navigation= (BottomNavigationView) findViewById(R.id.navigation);
            navigation.setRotation(90f);
            navigation.getLayoutParams().width=480;
            navigation.requestLayout();
            navigation.setY(600f);
            navigation.setX(-435f);
           // navigation.requestLayout();
            BottomNavigationMenuView menuView = (BottomNavigationMenuView) navigation.getChildAt(0);
            for (int i = 0; i < menuView.getChildCount(); i++) {
                final View iconView = menuView.getChildAt(i);
                iconView.setRotation(-90f);
            }
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            recreate();
        }
    }

and my XML is

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:text="@string/title_home"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

</android.support.constraint.ConstraintLayout>

Definitely, you have to change navigation.getLayoutParams().width, setX and setY according to your phone needs. You can create a function to calculate the position. Sorry its 10:30 in the day and was coding all night so going for rest, so couldn't write that function. But i would write that function if you want. Its what i got working for my phone Vivo Y51L, you can have look at screenshots.

Screenshots Landscape Portrait

Upvotes: 7

Pouya Danesh
Pouya Danesh

Reputation: 1627

i am afraid that BottomNavigationView only handles bottom of the page navigation you should create your own custom drawer or use one of the menus in this link further more if these didn't help you could see this documentation on how to handle different layouts

hope this helps

Upvotes: 0

Elio Lako
Elio Lako

Reputation: 1351

Since you can't customize BottomNavigation to be used in a vertical how it's wanted from you.. I would recommend (if you still haven't managed to fix it) switching to this library : SideMenu-Android Or you can create a customized Navigation Drawer.

Upvotes: 1

Related Questions