LayerDrawable 在 Android 中无法正常工作
我浏览了developer.android.com 上的LayerDrawable 教程,并为自己编写了这段代码:
Button b1 = (Button)findViewById(R.id.button2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ImageView iv1 = (ImageView)findViewById(R.id.imageView1);
Drawable []dr = new Drawable[2];
dr[0] = TestSpaceActivity.res.getDrawable(R.drawable.yellow_triangle);
dr[1] = TestSpaceActivity.res.getDrawable(R.drawable.red_triangle);
LayerDrawable ld=(LayerDrawable)res.getDrawable(R.drawable.bubble);
iv1.setImageDrawable(ld);
}
});
但不幸的是,它仅显示在dr[1] 中存储的图像。根据我的理解,我认为它应该显示两个图像叠加在一起。请帮助我解决这个问题,让我知道其中有什么问题,并告诉我我所理解的是否正确或错误。
问候..
Pavan Karanam
I went through the LayerDrawable tutorial from developer.android.com and wrote this code for myself :
Button b1 = (Button)findViewById(R.id.button2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ImageView iv1 = (ImageView)findViewById(R.id.imageView1);
Drawable []dr = new Drawable[2];
dr[0] = TestSpaceActivity.res.getDrawable(R.drawable.yellow_triangle);
dr[1] = TestSpaceActivity.res.getDrawable(R.drawable.red_triangle);
LayerDrawable ld=(LayerDrawable)res.getDrawable(R.drawable.bubble);
iv1.setImageDrawable(ld);
}
});
but unfortunately it is displaying only the image that is storted in dr[1]. as per my understanding i think it should display both the images overlayed on one other. kindly help me with this and let me know what is wrong in this and tell me if what i have understood is correct or wrong.
regards..
Pavan Karanam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不起作用,因为您从未设置可绘制对象。
It is not working because you never set the drawables.