嗨,我正在编写一个应用程序,我需要为一个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();
}
}
}
答案 0 :(得分:0)
我已经使用LayerDrawable和ImageView.setImageDrawable
轻松完成了