我是安卓的初学者。在这个项目中,我有BottomNavigationView
. 从一个视图切换到另一个视图时,我想为此添加cross-fade
动画。BottomNavigationView
下面是我的代码。
bottom_nav.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Content Container -->
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/colorWhite"
app:itemIconTint="@drawable/item_checked_color"
app:itemTextColor="@drawable/item_checked_color"
app:menu="@menu/bottom_navigation_main" />
</RelativeLayout>
我将上面的 xml 文件包含到 activity_main.xml
activity_main.xml
<RelativeLayout 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/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"/>
// other content
<include
layout="@layout/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
MainActivity.java
public class MyDashboardActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener {
private BottomNavigationView bottomNavigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bottomNavigationView = (BottomNavigationView)findViewById(R.id.bottom_navigation);
BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
loadBottomNavigation();
}
public void loadBottomNavigation(){
Menu bottomMenu = bottomNavigationView.getMenu();
if (bottomMenu != null){
for (int i=0; i< bottomMenu.size(); i++){
MenuItem bottomMenuItem = bottomMenu.getItem(i);
applyFontToMenuItem(bottomMenuItem);
MenuItem dashboard = bottomMenu.getItem(0);
dashboard.setChecked(true);
MenuItem expert = bottomMenu.getItem(2);
expert.setChecked(false);
}
}
bottomNavigationView.setOnNavigationItemSelectedListener(
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.action_1:
Intent intent = new Intent(getApplicationContext(), NewActivity.class);
intent.putExtra("idPatient", idPatient);
startActivity(intent);
break;
case R.id.action_2:
Intent intent1 = new Intent(MainActivity.this, FirstActivity.class);
intent1.putExtra("idPatient", idPatient);
startActivity(intent1);
break;
case R.id.action_3:
Intent intent2 = new Intent(MainActivity.this, SecondActivity.class);
String url = "https:rrrrrrr";
String activityName = "MainActivity";
intent2.putExtra("activity", activityName);
intent2.putExtra("linkUrl", url);
startActivity(intent2);
break;
}
return true;
}
});
}
}
cross-fade
在视图之间切换时如何添加动画?