开发者

LayerDrawable not working properly in android

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.getDrawab开发者_如何学Gole(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


It is not working because you never set the drawables.

    @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 = new LayerDrawable(dr);
        iv1.setImageDrawable(ld);
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜