簡體   English   中英

在功能android中加載R.drawable

[英]load R.drawable in function android

我有一個功能

 public void creacion_layout_items(R.drawable imagen_principal){
  LinearLayout _33_1_layout=(LinearLayout)findViewById(R.id.layout_principal);                               
        ImageView imagen=new ImageView(this);   
        LinearLayout.LayoutParams imagen_Params = new LinearLayout.LayoutParams(12,12);
        imagen.setLayoutParams(imagen_Params);
        imagen.setBackgroundResource(imagen_principal);
_33_1_layout.addView(imagen);
}

我想調用該函數

creacion_layout_items(R.drawable.all);

但不起作用

R.drawable.somethingint類型的。 R.drawable根本不是類型。 所以用

public void creacion_layout_items(int yourResDrawableId){
   ...
 imagen.setBackgroundResource(yourResDrawableId);
   ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM