开发者

Slide-down animation

I am trying to animate a TextView sliding down from behind an ImageView. I've got the following layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_开发者_Go百科content">
  <TextView
    android:id="@+id/description"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="16dp"
    android:layout_margin="16dp"
    android:layout_marginTop="-10dp"
    android:background="@drawable/image_background"
    android:visibility="invisible" 
    android:layout_below="@id/image"
    />
  <ImageView
    android:id="@+id/image"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/image_background"
    android:adjustViewBounds="true"
    android:layout_margin="6dp"
    android:layout_below="@id/question"
  />
</RelativeLayout>

I am using a RelativeLayout instead of a LinearLayout to get the description TextView to appear behind the ImageView (z-index-wise).

Note that the TextView can vary in the length of the text, and when filled in it is frequently longer than the image. There is also other views above and below that RelativeLayout.

I've tried with this animation

<set xmlns:android="http://schemas.android.com/apk/res/android">
  <translate android:fromYDelta="-100%p" android:toYDelta="0"
      android:duration="@android:integer/config_longAnimTime"/>
  <scale android:fromYScale="0.0" android:toYScale="1.0"
      android:duration="@android:integer/config_longAnimTime" />
</set>

...and using

descriptionView.Visibility = ViewStates.Visible;
Animation a = AnimationUtils.LoadAnimation(this, Resource.Animation.push_down);
descriptionView.StartAnimation(a);

However, this is choppy, and does not begin where I thought it would begin, nore does the scaling work. I've read about layout animations, and that the animation can be triggered automatically when the visibility changes, but I don't know how.

How do I get the animation to work, and is there an easier solution?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜