How to create vertical BottomNavigationView android?

后端 未结 5 1913
小蘑菇
小蘑菇 2021-02-08 16:06

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

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-08 16:39

    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

    
    
    
        
    
        
    
    
    

    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

提交回复
热议问题