2011-08-02 32 views
0

正常工作,我通过LayerDrawable教程就从developer.android.com并写了自己这个代码:LayerDrawable不是机器人

按钮B1 =(按钮)findViewById(R.id.button2);

b1.setOnClickListener(新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); 
     } 
    }); 

但不幸的是它显示的是仅在博士storted图像[1]。按照我的理解,我认为它应该显示两者图像覆盖在另一个。好心帮助我,让我知道什么是错在这一点,并告诉我,如果我所理解是正确的或错误的。

问候..

帕Karanam

+0

请发布定义drawable.bubble的XML。 – cdhabecker

回答

1

它不工作,因为您从未设置绘图。

@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); 
    } 
});