我猜我忽略了一些简单的事情,但我没有看到它。
我有一组图像视图,从visibility.gone过渡到visibility.visible,但是当我从我的代码设置属性时,图像视图就会弹出,它们不能平滑过渡。
更改可见性的代码只是:
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>
答案 0 :(得分:-1)
您应该使用ViewPropertyAnimator来实现此目的。以下是Google Android开发人员博客上的博文:Introducing ViewPropertyAnimator
这个想法是将动画实现为Fade In和Fade Out效果。代码将是这样的:
//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
找到