相关疑难解决方法(0)

Android:展开/折叠动画

假设我有一个垂直linearLayout:

[v1]
[v2]
Run Code Online (Sandbox Code Playgroud)

默认情况下,v1具有visibily = GONE.我想用扩展动画展示v1并同时向下推v2.

我试过这样的事情:

Animation a = new Animation()
{
    int initialHeight;

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        final int newHeight = (int)(initialHeight * interpolatedTime);
        v.getLayoutParams().height = newHeight;
        v.requestLayout();
    }

    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
        initialHeight = height;
    }

    @Override
    public boolean willChangeBounds() {
        return true;
    }
};
Run Code Online (Sandbox Code Playgroud)

但是使用这个解决方案,动画开始时我会闪烁.我认为这是由v1在应用动画之前显示完整大小引起的.

使用javascript,这是一行jQuery!用android做任何简单的方法吗?

animation android

435
推荐指数
18
解决办法
26万
查看次数

以编程方式调整布局大小(作为动画)

我想在Activity中调整一些布局的大小.

这是主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>
Run Code Online (Sandbox Code Playgroud)

如您所见,顶部和底部布局高度为0,中间布局覆盖所有位置.

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

我希望它看起来像一个动画.

我该怎么办?

谢谢

layout animation android android-animation

44
推荐指数
2
解决办法
5万
查看次数

Android:使用展开动画添加视图(不闪烁)

我想使用扩展动画向视图组添加视图,因此添加的视图开始非常小并占用越来越多的空间,直到达到其完整大小(可能在此过程中移动其他视图).

在尝试不同的方法后,我想出了下面的解决方案.投票,如果它可以帮助您或请发布更好的替代品.我相信必须有一个更简单的方法来做到这一点.

有关更多信息,请参阅此类此类的帖子.

这是我添加视图并启动动画的方法:

// Trick: set height to 1 so the view doesn't take its full size at the beginning.
// (0 doesn't work, I don't know why)
container.addView(view, LayoutParams.MATCH_PARENT, 1);
Animation expansion = createExpansion(view);
expansion.setDuration(200);
view.startAnimation(expansion);
Run Code Online (Sandbox Code Playgroud)

createExpansion()方法:

public static Animation createExpansion(View view) {

    return new SizedHeightScaleAnimation(view, 0, 1,
            Animation.RELATIVE_TO_SELF, 0f,
            Animation.RELATIVE_TO_SELF, 0f);
}
Run Code Online (Sandbox Code Playgroud)

最后是SizedHeightScaleAnimation动画类:

/**
 * Like {@link ScaleAnimation} for height scaling that also resizes the view accordingly,
 * so …
Run Code Online (Sandbox Code Playgroud)

layout animation android

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×3

animation ×3

layout ×2

android-animation ×1