重新调整布局编程(动画)布局、动画

由网友(厌恶的鬼)分享简介:我要调整一些布局在我的活动。I want to resize some layouts in my Activity.下面是主要的XML的code:Here is the code of the main XML:我要调整一些布局在我的活动。

I want to resize some layouts in my Activity.

下面是主要的XML的code:

Here is the code of the main XML:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/top"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="#3ee3e3" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/middle"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="#fe51e6" >
    </LinearLayout>
</LinearLayout>

正如你所看到的,顶部和底部布局的高度的是0,中间 布局覆盖了所有的地方。

As you can see, the top and bottom layouts height's is 0, and the middle layout covers all the place.

我想以编程方式减少中间版面大小,而增加的顶部 和底布局尺寸,直到所有的布局具有相同的高度。

I want to programatically decrease the middle layout size, while increase both the top and the bottom layout sizes, till all the layouts have the same height.

我想这是看起来像一个动画。

I want it to be look like an animation.

我应该怎么办呢?

感谢

推荐答案

我写了一个ResizeAnimation类似用途。这很简单,但成本高。

I wrote a ResizeAnimation for a similar purpose. It's simple but costly.

/**
 * an animation for resizing the view.
 */
public class ResizeAnimation extends Animation {
    private View mView;
    private float mToHeight;
    private float mFromHeight;

    private float mToWidth;
    private float mFromWidth;

    public ResizeAnimation(View v, float fromWidth, float fromHeight, float toWidth, float toHeight) {
        mToHeight = toHeight;
        mToWidth = toWidth;
        mFromHeight = fromHeight;
        mFromWidth = fromWidth;
        mView = v;
        setDuration(300);
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        float height =
                (mToHeight - mFromHeight) * interpolatedTime + mFromHeight;
        float width = (mToWidth - mFromWidth) * interpolatedTime + mFromWidth;
        LayoutParams p = mView.getLayoutParams();
        p.height = (int) height;
        p.width = (int) width;
        mView.requestLayout();
    }
}
阅读全文

相关推荐

最新文章