【问题标题】:Android ViewAnimator : animation while changing viewstub childAndroid ViewAnimator:更改viewstub子时的动画
【发布时间】:2011-10-20 15:19:42
【问题描述】:

这是我的问题:

我有一个像这样的 ViewAnimator:

<ViewAnimator
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/viewanimator">

    <ViewStub
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/form_viewstub"
        android:inflatedId="@+id/form_view"
        android:layout="@layout/form_layout"/>

    <ViewStub
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/history_viewstub"
        android:inflatedId="@+id/history_view"
        android:layout="@layout/history_layout"/>

    <ViewStub
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/call_viewstub"
        android:inflatedId="@+id/call_view"
        android:layout="@layout/call_layout"/>

</ViewAnimator>

当我为当前视图之后的视图设置动画时,没有问题。问题是,当我之前尝试为 viewtub 设置动画时,我看不到动画。这是一个具体的例子:

当我尝试使用以下动画为id/history_viewstub 设置动画并且id/call_viewstub 是当前显示的布局时,我什么都看不到(我想动画是在当前视图后面播放的)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromXScale="0.0"
        android:toXScale="1.0"
        android:fromYScale="0.0"
        android:toYScale="1.0"
        android:pivotX="1.0"
        android:pivotY="0.0"
        android:fillAfter="true"
        android:duration="600"/>
    <translate
        android:fromXDelta="100%"
        android:toXDelta="0"
        android:duration="600"/>
</set>

有人遇到过这个问题吗?

有没有办法像在 web 开发中一样为视图指定一个 z-index


编辑

使用ZAdjustment 属性并不能解决问题

【问题讨论】:

  • 您在使用showPrevious()showNext() 以及setInAnimationsetOutAnimation 吗?
  • 不,我正在使用 setDisplayedChild(int index)

标签: android android-layout z-index android-animation viewanimator


【解决方案1】:

我确定您已经解决了这个问题,但是由于没有答案...您应该可以使用android:zAdjustment="top"

【讨论】:

  • 尚未解决...我明天会尝试您的建议,当然。我必须以编程方式设置它,因为我不知道必须在顶部的视图......我会在尝试时告诉你;)
  • 使用 setZAdjustment(ZORDER_TOP) 运气好吗?
  • 没有解决我在 2011 年 10 月 22 日 11:19 编辑时提到的问题
【解决方案2】:

你可以使用这个View.bringToFront

此方法会将您的视图移动到子列表的末尾。所以它和其他视图索引会改变。小心这个。

【讨论】:

    【解决方案3】:

    在我看来,您实际上并没有使用ViewAnimator 类的功能,而只是使用了继承的FrameLayout 类。

    要为视图转换设置动画,您需要在ViewAnimator 上设置android:inAnimationandroid:outAnimation 属性,并使用setDisplayedChild()showNext()showPrevious() 从您的代码启动转换。

    【讨论】:

    • 所以我必须使用 FrameLayout 而不是 ViewAnimator ?
    • 因为我已经在使用viewAnimator.setInAnimation(inAnim);viewAnimator.setOutAnimation(outAnim);了,问题是如果我要动画的viewstub放在当前显示的child之前,动画就会出现在当前显示的child后面。 ..
    猜你喜欢
    • 1970-01-01
    • 2017-04-09
    • 2015-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多