2015-09-15 76 views
0

這裏是我的LinearLayout中生成的按鈕的ArrayList,事情是,我已經在24x24中指出了大小,但是當我模擬它時,它根本沒有調整大小。請幫我,我將不勝感激:d動態圖像按鈕不調整大小

public void generate_btnRemoveContact() 
    { 
     LinearLayout.LayoutParams lytContactParams=new LinearLayout.LayoutParams(24,24); 
     lytContactParams.weight=.5f; 
     btnRemoveContact.add(new ImageButton(getApplicationContext())); 
     btnRemoveContact.get(cntContact); 
     btnRemoveContact.get(cntContact).setScaleType(ImageView.ScaleType.FIT_CENTER); 
     btnRemoveContact.get(cntContact).setImageResource(R.drawable.ic_remove_circle_outline_red_24dp); 
     btnRemoveContact.get(cntContact).setBackgroundColor(Color.TRANSPARENT); 
     btnRemoveContact.get(cntContact).setTag(cntContact); 
     btnRemoveContact.get(cntContact).setId(cntContact); 

     btnRemoveContact.get(cntContact).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       for (int rmvCnt = v.getId(); rmvCnt < cntContact; rmvCnt++) { 
        Toast.makeText(getApplicationContext(), "you selected " + rmvCnt, Toast.LENGTH_LONG).show(); 
       } 
      } 
     });' 



     lytContact.addView(btnRemoveContact.get(cntContact)); 

     cntContact++; 

    } 

回答

0

從您發佈的代碼,你需要設置上的ImageButton的的LayoutParams:

btnRemoveContact.get(cntContact).setLayoutParams(lytContactParams);