Remover o modo Animation / Shifting do android BottomNavigationView [duplicado]
Esta pergunta já tem uma resposta aqui:
Como desativar o modo de mudança BottomNavigationView? 17 respostasEstou criando um aplicativo no qual tenho um BottomNavigationView. Tudo funciona bem até eu chegar à atividade.
A navegação é esta:
O problema é que ele tem essa animação padrão e empurra o elemento ativo toda vez mais alto que o resto.
Outro exemplo:
Então, minha pergunta é como se livrar dessa animação padrão e todos os itens são alinhados quando eu alterno entre eles?
Meu código:
public class MainActivity extends AppCompatActivity {
private BottomNavigationView bottomNavigationView;
private Fragment fragment;
private FragmentManager fragmentManager;
private FragmentTransaction transaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupBottomBar();
}
private void setupBottomBar() {
bottomNavigationView = (BottomNavigationView)findViewById(R.id.bottomBar);
fragmentManager = getSupportFragmentManager();
fragment = new CardDeckFragment();
transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.activity_main, fragment).commit();
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()){
case R.id.action_card_deck:{
Toast.makeText(MainActivity.this, "Card Deck Selected", Toast.LENGTH_SHORT).show();
fragment = new CardDeckFragment();
break;
}
case R.id.action_favorites:{
Toast.makeText(MainActivity.this, "Favorites Selected", Toast.LENGTH_SHORT).show();
fragment = new FavoritesFragment();
break;
}
case R.id.action_favorites_another:{
Toast.makeText(MainActivity.this, "Image Selected", Toast.LENGTH_SHORT).show();
fragment = new ImageFragment();
break;
}
case R.id.action_profile:{
Toast.makeText(MainActivity.this, "Profile Selected", Toast.LENGTH_SHORT).show();
fragment = new ProfileFragment();
break;
}
case R.id.action_menu:{
Toast.makeText(MainActivity.this, "Menu Selected", Toast.LENGTH_SHORT).show();
fragment = new MenuFragment();
break;
}
}
transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.activity_main, fragment).commit();
return true;
}
});
}
}
e meu layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.realtimegaming.androidnative.testproject.MainActivity">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomBar"
android:layout_alignParentBottom="true"
android:background="@color/brown"
android:layout_gravity="bottom"
android:gravity="bottom"
android:layout_marginTop="?attr/actionBarSize"
app:itemBackground="@color/colorPrimary"
app:menu="@menu/bottom_navigation_main"
app:itemIconTint="@color/white"
android:fitsSystemWindows="true"
android:animateLayoutChanges="false"
android:splitMotionEvents="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>