使用XML在Android中的布局中显示动画PNG图像

sah*_*hil 4 xml android image

XML可以用于在我的Android布局中显示动画图像吗?

Chr*_*CVB 17

布局

<ImageView
    android:layout_width="82dip"
    android:layout_height="50dip"
    android:layout_centerInParent="true"
    android:background="@drawable/spinner"
    android:id="@+id/splashSpinner"/>
Run Code Online (Sandbox Code Playgroud)

可绘制

<?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/anim__000" android:duration="100" />
    <item android:drawable="@drawable/anim__001" android:duration="100" />
    <item android:drawable="@drawable/anim__002" android:duration="100" />
    <item android:drawable="@drawable/anim__003" android:duration="100" />
    <item android:drawable="@drawable/anim__004" android:duration="100" />
    <item android:drawable="@drawable/anim__005" android:duration="100" />
    <item android:drawable="@drawable/anim__006" android:duration="100" />
    <item android:drawable="@drawable/anim__007" android:duration="100" />
    <item android:drawable="@drawable/anim__008" android:duration="100" />
    <item android:drawable="@drawable/anim__009" android:duration="100" />
    <item android:drawable="@drawable/anim__010" android:duration="100" />
    <item android:drawable="@drawable/anim__011" android:duration="100" />
</animation-list>
Run Code Online (Sandbox Code Playgroud)

JAVA

    this.spinner = this.view.findViewById(R.id.splashSpinner);

    this.spinner.post(new Runnable()
    {
        @Override
        public void run()
        {
            AnimationDrawable spinnerAnim = (AnimationDrawable) spinner.getBackground();
            if (!spinnerAnim.isRunning())
            {
                spinnerAnim.start();
            }
        }
    });
Run Code Online (Sandbox Code Playgroud)

  • 你不是在谈论你的问题中的gif ...在android项目中添加一个gif是不可能的. (3认同)
  • 轻松拍摄动画GIF并在adobe photoshop中打开.它会显示所有图层.将每个图层保存为png文件.然后使用此响应中的示例来为png设置动画. (2认同)