이렇게하는 방법에 대한 좋은 예를 찾을 수 없습니다.애니메이션을 사용하여 레이아웃 높이를 확장하는 방법은 무엇입니까?
x 높이를 기준으로 RelativeLayout을 설정했습니다.
높이를 x + y 높이로 확장하는 버튼을 추가하고 싶습니다.
나를 프로그래밍 방식으로 수행하는 방법에 대한 좋은 예를 참조 할 수 있습니까?
이렇게하는 방법에 대한 좋은 예를 찾을 수 없습니다.애니메이션을 사용하여 레이아웃 높이를 확장하는 방법은 무엇입니까?
x 높이를 기준으로 RelativeLayout을 설정했습니다.
높이를 x + y 높이로 확장하는 버튼을 추가하고 싶습니다.
나를 프로그래밍 방식으로 수행하는 방법에 대한 좋은 예를 참조 할 수 있습니까?
있는 공식 문서
입니다 필요합니다. 하지만 여기서 정확한 높이를 알아야합니다.
public class LayoutAnimationActivity extends Activity
{
RelativeLayout ril1;
Button btn;
int initialHeight;
int actualHeight;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
ril1=(RelativeLayout)findViewById(R.id.relativeLayout1);
btn=new Button(this);
btn.setWidth(100);
btn.setHeight(200);
btn.setText("Button");
actualHeight=210;
Ani a=new Ani();
a.setDuration(2000);
ril1.startAnimation(a);
}
class Ani extends Animation
{
public Ani() {
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newHeight;
newHeight = (int)(initialHeight * interpolatedTime);
ril1.removeAllViews();
btn.setWidth(100);
btn.setHeight(300);
btn.setText("as");
ril1.addView(btn);
ril1.getLayoutParams().height = newHeight;
ril1.requestLayout();
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
initialHeight = actualHeight;
}
@Override
public boolean willChangeBounds() {
return true;
}
};
}
당신은 규모 애니메이션 here 아래로 새로운 편집 답변을 아래에 확인하시기 바랍니다이 코드에서
private void animate() {
ImageView imageView = (ImageView) findViewById(R.id.ImageView01);
ScaleAnimation scale = new ScaleAnimation((float)1.0, (float)1.5, (float)1.0, (float)1.5);
scale.setFillAfter(true);
scale.setDuration(500);
imageView.startAnimation(scale);
}
가장 가까운 해결책을 표시했습니다. 이것은 정확한 해결책입니다. 나는 똑같은 문제가 있었다. 바라건대이 대답은 다른 사람들을 도울 것입니다.
1) XML 레이아웃 파일에 android:animateLayoutChanges="true"
을 설정합니다
인스턴스화 ResizeAnimation
ResizeAnimation resizeAnimation = new ResizeAnimation(
view,
targetHeight,
startHeight
);
resizeAnimation.setDuration(duration);
view.startAnimation(resizeAnimation);
ResizeAnimation
클래스는 Animation
클래스없이이 작업을 수행하는이
public class ResizeAnimation extends Animation {
final int targetHeight;
View view;
int startHeight;
public ResizeAnimation(View view, int targetHeight, int startHeight) {
this.view = view;
this.targetHeight = targetHeight;
this.startHeight = startHeight;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newHeight = (int) (startHeight + targetHeight * interpolatedTime);
//to support decent animation, change new heigt as Nico S. recommended in comments
//int newHeight = (int) (startHeight+(targetHeight - startHeight) * interpolatedTime);
view.getLayoutParams().height = newHeight;
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;
}
}
두 가지 간단한 방법과 같아야합니다
2) 피벗 어디, 기본값은 내 경험에서 거의 절대 당신이 원하는없는 중간에까지 확장하는보기를 알려주는 VIEWPROPERTY 애니메이터에게
layout.setPivot(0);
layout.animate().scaleY(scaleFactor).setDuration(500);
를 사용합니다. 기간은 선택 사항입니다 (기본값 = 1000). 여기
final Button button1 = (Button) view.findViewById(R.id.button);
final CollapseAnimator animator = new CollapseAnimator(topLayout);
final ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int mHeight = button1.getMeasuredHeight();
KLog.i("onGlobalLayout() mHeight:" + mHeight);
animator.setValues(mHeight*2, mHeight);
}
};
button1.getViewTreeObserver().addOnGlobalLayoutListener(listener);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
view.post(new Runnable() {
@Override
public void run() {
button1.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
animator.collapse();
}
});
}
});
및 클래스
public class CollapseAnimator {
private View view;
private boolean collapse=true;
private int duation=300;
private int destHeight=300;
private ValueAnimator animator;
private int originHeight=0;
private int from=0;
private int to=0;
public CollapseAnimator(View view) {
this.view = view;
}
public void setValues(int destHeight,int originHeight){
this.destHeight = destHeight;
this.originHeight=originHeight;
from=originHeight;
to=originHeight;
}
public void collapse(){
from=to;
if(collapse){
to=destHeight;
collapse=false;
}else{
to=originHeight;
collapse=true;
}
KLog.i("from:" + from+",to:"+to);
animator = ValueAnimator.ofInt(from, to);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int val = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.height = val;
view.setLayoutParams(layoutParams);
}
});
animator.setDuration(duation);
animator.start();
}
}
확인 확장 및 축소 솔루션을 내가 한 : http://stackoverflow.com/questions/20973089/android-add-view-with-expand- 애니메이션없이 - 깜박임 –
http://stackoverflow.com/a/8162779/5996106 최상의 솔루션 –