我想使用一個按鈕添加一個圖像,然後在一個指定的 relativeLayout 上顯示縮略圖。
public void showViewOfReceiptFromSelecting(String uriString)
{
byte[] imageData = null;
try
{
InputStream fis = this.getContentResolver().openInputStream(Uri.parse((uriString)));
Bitmap imageBitmap = BitmapFactory.decodeStream(fis);
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, 40, 40, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
imageData = baos.toByteArray();
ImageView image = new ImageView(this);
image.setImageBitmap(imageBitmap);
image.setId(counterOfReceipts);
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
rlp.addRule(RelativeLayout.RIGHT_OF, counterOfReceipts - 1);
myRelalativelayout.addView(image, rlp); // a relative Layout i already defined earlier in the code
counterOfReceipts = counterOfReceipts + 1 ;
}
catch(IOException e) {
e.printStackTrace();
}
}
現在的問題是,當我試圖再添加一個縮略圖時,它就會取代了之前的那個舊的。我改怎麼處理這個問題?
rlp屬性是否是需要設置為ALIGN_WITH_PARENT_LEFT或者ALIGN_WITH_PARENT_RIGHT