1
我需要更改Drawable []的第二層的大小。 我有以下代碼:使用2層從Drawable []更改圖層的大小
hLayout.postDelayed(new Runnable() {
DisplayMetrics metrics = getActivity().getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;
@Override
public void run() {
if (coupons != null) {
int coupSize = coupons.size();
final int itemWidth = (width/3);
final int itemHeight = (height/3);
hLayout.removeAllViews();
for (int i = 0; i < coupSize; i++) {
Coupon coupon = coupons.get(i);
if (coupon.getImage() != null) {
RelativeLayout parent = new RelativeLayout(getActivity());
RelativeLayout.LayoutParams linearparams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
parent.setLayoutParams(linearparams);
final CheckBox cb = new CheckBox(getActivity());
final ImageView iv = new ImageView(getActivity());
// iv.setScaleType(ScaleType.CENTER_INSIDE);
LayoutParams checkBoxParams = new LayoutParams();
cb.setId(i);
checkBoxParams.height = LayoutParams.WRAP_CONTENT;
checkBoxParams.width = LayoutParams.WRAP_CONTENT;
cb.setOnCheckedChangeListener(changeListener);
RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(itemWidth, itemHeight);
imageParams.height = itemHeight;
imageParams.width = itemWidth;
imageParams.addRule(RelativeLayout.BELOW, cb.getId());
if (cb.getId() == 0) {
imageParams.topMargin = 72;
}
parent.addView(cb, checkBoxParams);
parent.addView(iv, imageParams);
hLayout.addView(parent);
//ImageUtil.loadImage(coupon.getImage(), iv, itemWidth, itemHeight, "", false, getActivity());
Bitmap b =Util.generateEAN("9310779300005", getActivity());
Drawable d = new BitmapDrawable(getResources(),b);
System.out.println("------------b : "+b);
//iv.setImageBitmap(b);
Resources r = getResources();
Drawable[] layers = new Drawable[2];
layers[0] = r.getDrawable(R.drawable.coupon1);
layers[1] = d;
layers[1].setAlpha(200);
LayerDrawable layerDrawable = new LayerDrawable(layers);
iv.setImageDrawable(layerDrawable);
}
}
}
}
}, 200);
我試圖與層[1] .setBounds(左,上,右,下);但沒有運氣,我不知道還有什麼要嘗試。
這實在是一條評論,而不是對問題的回答。請使用「添加評論」爲作者留下反饋。 – Thor 2012-08-17 10:20:47
@Thor這是一個答案,只是不是一個非常有用或詳細的答案 – Craigy 2012-08-17 16:38:00