我需要帮助。它说:错误:找不到符号fruitimage.setbackgroundresource(r.drawable.myfruits);^符号:变量位置:可绘制类
fae0ux8s1#
--这是密码
qv7cva1a2#
--
myfruits.xml (located at drawable) <?xmlversion="1.0"encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/img_grapes" android:duration="200"/> <item android:drawable="@drawable/img_lemon" android:duration="200"/> <item android:drawable="@drawable/img_orange" android:duration="200"/> <item android:drawable="@drawable/img_pear" android:duration="200"/> <item android:drawable="@drawable/img_strawberry" android:duration="200"/> </animation-list>
llew8vvj3#
-----主要活动
dkqlctbz4#
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView fruitImage = (ImageView) findViewById(R.id.imgFruit); fruitImage.setBackgroundResource(R.drawable.myfruits); fruitAnimation = (AnimationDrawable) fruitImage.getBackground(); }
7vhp5slm5#
这是解释。https://developer.android.com/reference/android/graphics/drawable/animationdrawable在代码中,必须更改myfruits.xml。
<animation-list android:id="@+id/selected" android:oneshot="false"> <item android:drawable="@drawable/img_grapes" android:duration="200"/> <item android:drawable="@drawable/img_lemon" android:duration="200"/> <item android:drawable="@drawable/img_orange" android:duration="200"/> <item android:drawable="@drawable/img_pear" android:duration="200"/> <item android:drawable="@drawable/img_strawberry" android:duration="200"/> </animation-list>
-----主要活动---
ImageView fruitImage = (ImageView) findViewById(R.id.imgFruit); fruitImage.setBackgroundResource(R.drawable.myfruits); AnimationDrawable fruitAnimation = (AnimationDrawable) fruitImage.getBackground(); fruitAnimation.start();
5条答案
按热度按时间fae0ux8s1#
--这是密码
qv7cva1a2#
--
llew8vvj3#
-----主要活动
dkqlctbz4#
7vhp5slm5#
这是解释。
https://developer.android.com/reference/android/graphics/drawable/animationdrawable
在代码中,必须更改myfruits.xml。
-----主要活动---