gpt4 book ai didi

java - 未找到资源异常将可绘制动画加载到 ImageView 中

转载 作者:数据小太阳 更新时间:2023-10-29 02:45:09 25 4
gpt4 key购买 nike

我正在尝试为我在 Activity 中用作背景的 ImageView 制作动画,但应用程序在加载 Activity 时崩溃。所有图像和 .xml 文件都在 drawable-hdpi 文件夹中,所以我不确定为什么找不到它。如果有更好的方法将动画设置为 Activity 背景,请告诉我。

这是我的动画 .xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/bow1" android:duration="60" />
<item android:drawable="@drawable/bow2" android:duration="60" />
<item android:drawable="@drawable/bow3" android:duration="60" />
<item android:drawable="@drawable/bow4" android:duration="60" />
<item android:drawable="@drawable/bow5" android:duration="60" />
<item android:drawable="@drawable/bow6" android:duration="60" />
<item android:drawable="@drawable/bow7" android:duration="60" />
<item android:drawable="@drawable/bow8" android:duration="60" />
<item android:drawable="@drawable/bow9" android:duration="60" />
</animation-list>

这是我用来尝试运行它的代码:

public class MainActivity extends Activity {

ImageView bground;
AnimationDrawable bganim;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.activity_main);

bground = (ImageView)findViewById(R.id.background);
bground.setBackgroundResource(R.drawable.bowanimbg);
bganim = (AnimationDrawable) bground.getBackground();
bganim.start();
}

java.lang.RuntimeException:无法启动 Activity ComponentInfo{com.example.lucidity/com.example.lucidity.MainActivity}:android.content.res.Resources$NotFoundException:文件 res/drawable-xxhdpi/来自可绘制资源 ID #0x7f02000b 的 bowanimbg.xml

最佳答案

我会把它放在评论中,但不幸的是我没有足够高的代表。所以我会尽力解决这个问题。

您提到所有图像都存在于 drawable-hdpi 文件夹中。但是,如果您注意到该错误,它似乎正在搜索 res/drawable-xxhdpi 文件夹中的文件。我的建议是将 -hdpi 文件夹中的 .xml 文件复制到 -xxhdpi 文件夹中,看看它是否有效!

关于java - 未找到资源异常将可绘制动画加载到 ImageView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24225882/

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