gpt4 book ai didi

android - 透明背景帧动画

转载 作者:行者123 更新时间:2023-11-29 17:47:55 26 4
gpt4 key购买 nike

我想使用进度条之类的动画。

我有 xml 文件 prog_drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="@drawable/progress01"
android:duration="100"/>
<item
android:drawable="@drawable/progress02"
android:duration="100"/>
<item
android:drawable="@drawable/progress03"
android:duration="100"/>
<item
android:drawable="@drawable/progress04"
android:duration="100"/>
<item
android:drawable="@drawable/progress05"
android:duration="100"/>
</animation-list>

文件 progress0x.png 看起来像这样(例如)

png with transparent background

此文件中的背景是透明的。

在 Activity 的布局 xml 我有 imageview

<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:id="@+id/tv_logo2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/iv_pb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_logo2"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@android:color/transparent"
android:contentDescription="@string/app_name" />
</RelativeLayout>

然后在java文件中

AnimationDrawable ad;
ImageView iv_pb;
...
iv_pb = (ImageView)findViewById(R.id.iv_pb);
iv_pb.setBackgroundResource(R.drawable.prog_drawable);

ad = (AnimationDrawable)iv_pb.getBackground();
ad.start();

当我启动我的应用程序时,我看到了这个动画,但背景是黑色的。如何获得透明背景?

最佳答案

即使您将 android:background="@android:color/transparent" 设置为您的 ImageView 以获得透明背景,但调用 iv_pb.setBackgroundResource( R.drawable.prog_drawable); 覆盖它,导致你的 animation-drawable 被设置为新的背景。

因此,最终您需要在图像文件中实现透明度。确保所有文件都在 .png 中且背景设置为透明。

关于android - 透明背景帧动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25117764/

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