【问题标题】:load R.drawable in function android在函数android中加载R.drawable
【发布时间】:2014-02-07 21:05:48
【问题描述】:

我有一个函数

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

但不起作用

【问题讨论】:

    标签: android function drawable r.java-file


    【解决方案1】:

    R.drawable.something 属于 int 类型。 R.drawable 根本不是类型。 所以使用

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

    【讨论】:

      猜你喜欢
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      相关资源
      最近更新 更多