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

dynamicSpaceただし、それは実際にはビューのサイズを変更しません。特にremainingSpace. ビューの移動をアニメーション化するだけdynamicSpaceです。しかし、ビューの「コンテナ」には、最初からすでにスペースが占有されています。

正しいのは、ライム色dynamicSpaceが 0px で始まり、ピンク色remainingSpaceが引き継ぐため、その間に灰色のスペースがありません。

4

2 に答える 2

0

ビューのスケーリング

あなたは時間tLinearInterpolatorでそれをやっていると言っているので、 aがベストのように聞こえます。

于 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 に答える