嗨,我正在编写一个应用程序,我需要为单个 ImageView 提供两种不同的背景;但是,我不知道该怎么做。
就我而言,我需要将动画和背景图像设置为单个 ImageView;但它只显示动画而不是图像背景。
我已将图像背景写为ic_launcher
图像,但它没有显示,只有动画显示。我需要同时使用相同的 ImageView 显示。谁能帮我?
我的代码:
public class MainActivity extends Activity {
AnimationDrawable Tranninganimation3;
ImageView unlockimg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Tranninganimation3 = new AnimationDrawable();
Tranninganimation3.setOneShot(false);
new playninzi3().onPreExecute();
unlockimg=(ImageView)findViewById(R.id.img);
unlockimg.setBackgroundResource(R.drawable.ic_launcher);
unlockimg.setBackgroundDrawable(Tranninganimation3);
unlockimg.post(new Starter3());
}
public class playninzi3 extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
try {
Tranninganimation3.addFrame(
getResources()
.getDrawable(R.drawable.glow_animated000copy), 150);
Tranninganimation3.addFrame(
getResources()
.getDrawable(R.drawable.glow_animated002copy), 150);
Tranninganimation3.addFrame(
getResources()
.getDrawable(R.drawable.glow_animated004copy), 150);
Tranninganimation3.addFrame(
getResources()
.getDrawable(R.drawable.glow_animated006copy), 150);
Tranninganimation3.addFrame(
getResources()
.getDrawable(R.drawable.glow_animated008copy), 150);
Tranninganimation3.addFrame(
getResources()
.getDrawable(R.drawable.glow_animated010copy), 150);
Tranninganimation3.addFrame(
getResources()
.getDrawable(R.drawable.glow_animated012copy), 150);
Tranninganimation3.addFrame(
getResources()
.getDrawable(R.drawable.glow_animated014copy), 150);
} catch (Exception e) {
}
}
@Override
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
return null;
}
}
class Starter3 implements Runnable {
@Override
public void run() {
Tranninganimation3.start();
}
}
}