Chr*_*han 16 android android-animation android-layout layoutparams
在我的应用程序中有一个LinearLayout,其布局高度为0.当我单击按钮时,此布局高度应为LayoutParams.WRAP_CONTENT.这是我在onclicklistner中使用的代码.
LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
slider.setLayoutParams(lp);
Run Code Online (Sandbox Code Playgroud)
我想动画这个.如何将动画设置为滑块.
Kai*_*Kai 25
我想你只想动画从0高度到最终高度的视图,你可以用自定义动画做到这一点:
public class ShowAnim extends Animation {
int targetHeight;
View view;
public ShowAnim(View view, int targetHeight) {
this.view = view;
this.targetHeight = targetHeight;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
view.getLayoutParams().height = (int) (targetHeight * interpolatedTime);
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;
}
}
Run Code Online (Sandbox Code Playgroud)
并在您的代码中执行此操作以启动动画:
Animation ani = new ShowAnim(headerView, 100/* target layout height */);
ani.setDuration(2000/* animation time */);
headerView.startAnimation(ani);
Run Code Online (Sandbox Code Playgroud)
Shr*_*jan -1
如果您想为您的布局实现滑块动画,请参阅此演示。
更新
另请参阅http://www.inter-fuser.com/2009/07/android-transistions-slide-in-and-slide.html
希望它能帮助你。
如果没有,请告诉我。
谢谢。享受。:)
| 归档时间: |
|
| 查看次数: |
20383 次 |
| 最近记录: |