开发者

How to scale View / ViewGroup - animate layout in a proper way?

开发者 https://www.devze.com 2023-02-26 18:13 出处:网络
In a few words, I want to scale view - in the s开发者_StackOverflow中文版ame way that Android Market does it, when you click the \"More\" button, on the for examplae \'Description\'.

In a few words, I want to scale view - in the s开发者_StackOverflow中文版ame way that Android Market does it, when you click the "More" button, on the for examplae 'Description'.

I figure it out, that the Android Market has the layout of following structure :

    <FrameLayout
    android:id="@+id/artists_frame"
    android:layout_width="fill_parent"
    android:layout_height="64dip"
    android:layout_below="@id/something1"
    android:layout_above="@id/something2"

    >

<!-- Some view there, which height >> 64dip -->

    </FrameLayout>

So, I've tried various Animations / LayoutAnimations on the FrameLayout (via view.setAnimation(), view.setLayoutAnimation() and ScaleAnimation), but the effect is always the same : the view animates, but it's real layout_height after scaling is still the same (so the position of the other views, that depend on the given FrameLayout, remain the same).

After that, I've thought - I change in the loop the layout_height of the given FrameLayout:

layoutParams = view.getLayoutParams()
layoutParams.height = scaleTo;
layout.setLayoutParams(layoutParams);

I've it got animating, market-like view, but the cost (performance!!!) is way to high...

So, the question is : Is there any other, proper way to scale (change e.g. height from 50dip to 200dip) the given View / ViewGroup so that the position of the views below the animating view also changes?


As Chet Haase says in this blog post: http://android-developers.blogspot.com/2011/02/animation-in-honeycomb.html

"...Finally, the previous animations changed the visual appearance of the target objects... but they didn't actually change the objects themselves..."

Since what your need is only visual, instead of changing the view's LayoutParameters I would animate the view in the bottom as well with a translate using android:fillAfter for both.

0

精彩评论

暂无评论...
验证码 换一张
取 消