嗨,我正在借用Seth在此处找到的方法来为我的 viewGroups 设置动画。它工作得很好,但方向错误——这是我第一次使用/扩展动画类,我不知道如何减小视图的大小——这会扩展它。
下面是课程以及我如何使用它。任何帮助将不胜感激。
public class ContainerAnim extends Animation {
int targetWidth;
View view;
boolean opened;
public ContainerAnim(View v, int targetWidth, boolean opened) {
this.view = v;
this.targetWidth = targetWidth;
this.opened = opened;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newWidth;
if (opened) {
newWidth = (int) (targetWidth * interpolatedTime);
} else {
newWidth = (int) (targetWidth * (1 - interpolatedTime));
}
view.getLayoutParams().width = newWidth;
view.requestLayout();
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
@Override
public boolean willChangeBounds() {
return true;
}
}
用法:
... case R.id.menu_shrink:
FragmentTransaction ft = getFragmentManager().beginTransaction();
FrameLayout frame = (FrameLayout) findViewById(R.id.listFragment_container);
ContainerAnim set = new ContainerAnim(frame, 100, true);
set.setDuration(200);
LayoutAnimationController c = new LayoutAnimationController(set,
0.25f);
frame.setLayoutAnimation(c);
frame.startLayoutAnimation();
ft.commit();
...