我尝试在2个布局之间设置自定义动画。
public class MainActivity extends FragmentActivity {
View menu = null;
ViewGroup parent = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_models);
//initialize the container and his parent
menu = findViewById(R.id.menu_model);
parent = (ViewGroup) menu.getParent();
//set transition
LayoutTransition lt = new LayoutTransition();
lt.enableTransitionType(LayoutTransition.CHANGING);
parent.setLayoutTransition(lt);
restoreMenu(null);
}
//display second menu
public void changeMenu(View view) {
int index = parent.indexOfChild(menu);
View old = menu;
menu = getLayoutInflater().inflate(R.layout.menu_2, parent, false);
parent.addView(menu, index);
parent.removeView(old);
}
//display first menu
public void restoreMenu(View view) {
int index = parent.indexOfChild(menu);
View old = menu;
menu = getLayoutInflater().inflate(R.layout.menu_1, parent, false);
parent.addView(menu, index);
parent.removeView(old);
}
}
正如您所见,我正在使用LayoutTransition
效果LayoutTransition.CHANGING
。
但我希望它看起来像这样:
我的旧菜单离开左边,我的新菜单来自右边。
你有什么想法我怎么能这样做? LayoutTransition
可以做到吗?
答案 0 :(得分:0)
使用TranslateAnimation
定义幻灯片放入和滑出动画,然后使用
overridePendingTransition(int enterAnim, int exitAnim)
这http://developer.android.com/reference/android/app/Activity.html#overridePendingTransition(int,int)