gpt4 book ai didi

android - 布局更改不使用 animateLayoutChanges=true 设置动画?

转载 作者:太空宇宙 更新时间:2023-11-03 11:25:03 26 4
gpt4 key购买 nike

我猜我忽略了一些简单的事情,但我没有看到。

我有一组从 visibility.gone 过渡到 visibility.visible 的 ImageView ,但是当我从我的代码中设置属性时, ImageView 只是弹出,它们不会平滑过渡。

改变可见性的代码就是:

              for (ImageView button : buttons.values()) {
button.setVisibility(View.VISIBLE); }


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toc_picker"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/junglebackground"
android:gravity="top"
android:orientation="vertical"
android:visibility="visible"
android:animateLayoutChanges="true"

android:alpha="1">

<LinearLayout
android:baselineAligned="false"

android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:orientation="horizontal"
android:alpha="1">

<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.025">

</LinearLayout>

<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.225">

<ImageView
android:id="@+id/TOCR1C1"
android:layout_width="175dp"
android:layout_height="175dp"

android:scaleType="centerCrop"
android:src="@drawable/ff_balloon"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>

<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.225">
<ImageView
android:id="@+id/TOCR1C2"
android:layout_width="175dp"
android:layout_height="175dp"
android:src="@drawable/ff_anteater"
android:scaleType="centerCrop"

android:layout_centerInParent="true"
android:visibility="gone" />

</RelativeLayout>

<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.225"
>
<ImageView
android:id="@+id/TOCR1C3"
android:layout_width="175dp"
android:layout_height="175dp"
android:src="@drawable/ff_birds"
android:scaleType="centerCrop"
android:background="@android:color/white"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>

<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.225"
>
<ImageView
android:id="@+id/TOCR1C4"
android:layout_width="175dp"
android:layout_height="175dp"
android:src="@drawable/empty_image"
android:scaleType="centerInside"
android:background="@android:color/white"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>

<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.025"
></LinearLayout>

</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:orientation="horizontal"
>

<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.025"
></LinearLayout>

<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.225"
android:visibility="visible">

<ImageView
android:id="@+id/TOCR2C1"
android:layout_width="175dp"
android:layout_height="175dp"
android:src="@drawable/empty_image"
android:scaleType="centerInside"
android:background="@android:color/white"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>

<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.225"
>
<ImageView
android:id="@+id/TOCR2C2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/chimp_frame_toc"
android:scaleType="centerInside"
android:background="@android:color/transparent"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>

<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.225"

>
<ImageView
android:id="@+id/TOCR2C3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/dreams_frame_toc"
android:scaleType="centerInside"
android:background="@android:color/transparent"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>

<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.225"
>
<ImageView
android:id="@+id/TOCR2C4"
android:layout_width="175dp"
android:layout_height="175dp"
android:src="@drawable/empty_image"
android:scaleType="centerInside"
android:background="@android:color/white"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>

<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="0.025"
></LinearLayout>

</LinearLayout>
</LinearLayout>

最佳答案

您应该为此目的使用 ViewPropertyAnimator。这是 Google Android 开发者博客上的一篇博文:Introducing ViewPropertyAnimator

想法是将动画实现为淡入淡出效果。代码将是这样的:

//fade out 

for (ImageView button : buttons.values()) {

ObjectAnimator fadeOut = ObjectAnimator.ofFloat(button,
"alpha", 0f);
fadeOut.setDuration(2000);
fadeOut.start();
}

//fade in

for (ImageView button : buttons.values()) {

ObjectAnimator fadeIn = ObjectAnimator.ofFloat(aniView, "alpha",
0f, 1f);
fadeIn.setDuration(2000);
fadeIn.start();
}

查看博客文章以下载示例代码和视频演示。

另一个教程可以在 Vogella Android Animation 上找到

关于android - 布局更改不使用 animateLayoutChanges=true 设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28015174/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com