0
我是初學者到android。在這個項目中,我有BottomNavigationView
。從一個視圖切換到另一個視圖時,我想將cross-fade
動畫添加到此BottomNavigationView
。以下是我的代碼。android - 淡入淡出動畫到底部導航視圖
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
動畫?
什麼是淡入淡出你想要的看法?你需要更具體然後,如果你需要幫助 –
@MosheEdri:對所有的意見。它的材料設計標準 –
我只看到你的代碼中的一個視圖我問我的方式 –