2011-08-02 85 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); 
    } 
});