0

我有这样的视图布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@color/light_gray"
    android:padding="5dip">

    <View android:id="@+id/fixedSpace" android:layout_width="fill_parent"
        android:layout_height="50dip" android:background="@color/aqua"
        android:layout_alignParentBottom="true" android:clickable="true"
        android:onClick="onClickStartAnimation" />

    <View android:id="@+id/dynamicSpace" android:layout_width="fill_parent"
        android:layout_height="200dip" android:background="@color/lime"
        android:layout_above="@id/fixedSpace" />


    <View android:id="@+id/remainingSpace" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:background="@color/pink"
        android:layout_alignParentTop="true" android:layout_above="@id/dynamicSpace" />


</RelativeLayout>

我想要实现的基本上是随着dynamicSpace时间的推移t的增长/收缩行为。使用动画,我可以制作以下内容:

t=1:

t=1

t=2:

t=2

t=3:

t=3

但是,这并没有真正调整我的观点,特别是dynamicSpaceremainingSpace. 它只是动画视图dynamicSpace移动。但是视图“容器”从一开始就已经占据了空间。

正确的是石灰色dynamicSpace以 0px 开头,粉红色remainingSpace接管,因此两者之间没有灰色空间。

4

2 回答 2

0

缩放视图

既然你说你是在t时间内做的,那么听起来 aLinearInterpolator是最好的。

于 2011-06-15T17:01:48.150 回答
0

编辑:我尝试用AsyncTask线程替换下面的内容,它更流畅。我认为关键是我让线程在后台运行,并在我想调整大小时使用它,从而减少开销


创建一个自定义 AnimationListener 并将调整视图大小的代码放在 onAnimationRepeat 方法中。

然后做一个虚拟动画并将动画上的重复设置为无限。一旦视图达到最终大小,将动画的重复计数设置为零(再次在 onAnimationRepeat 中):

class ResizeAnimationListener implements AnimationListener{

int finalHeight; // max Height
int resizeAmount; // amount to resize each time
View view; // view to resize

public ResizeAnimationListener(int finalHeight; View view, int resizeAmount) {
    super();
    finalHeight; = finalHeight; 
    this.resizeAmount = resizeAmount;
    this.view = view;

}

@Override
public void onAnimationEnd(Animation animation) {

}

@Override
public void onAnimationRepeat(Animation animation) {

    int newHeight;
    int currentHeight;

    current = view.getMeasuredHeight();

    newHeight= currentHeight+ resizeAmount;
    if(newHeight> finalHeight){
        // check if reached final height

        // set new height to the final height
        newHeight = finalHeight;
        // set repeat count to zero so we don't have any more repeats
        anim.setRepeatCount(0);

    }

    // set new height
    LayoutParams params = view.getLayoutParams();                                           
    params.height = newHeight;
    v.setLayoutParams(params);                                      

}

@Override
public void onAnimationStart(Animation animation) {

}

};

class DummyAnimation extends Animation{}


float frameRate = 1000/30;                              
DummyAnimation anim = new DummyAnimation();
anim.setDuration((long)frameRate);                          
anim.setRepeatCount(Animation.INFINITE);
ResizeAnimationListener animListener = new ResizeAnimationListener(((View)view.getParent()).getHeight(), view, 25);
anim.setAnimationListener(animListener);

view.startAnimation(anim);

我在自己的应用程序上完成了这项工作。但是,锚定到我正在调整大小的视图的视图(因此当我调整视图大小时在屏幕上移动)似乎出现了故障。可能与重复调整大小有关,而不是其他任何事情,但只是一个警告。也许其他人知道为什么?

于 2011-11-11T15:00:33.097 回答