When we are developing applications, especially image browsers or file browsers, involving image or file management, we will inevitably need to process them in batches and use the multiple choice function. How can we visually display the selected file to the user? We can change the font color of the file name to mark it, but it is not very obvious, it is better to display a check box on the file or image icon to select a table. In the layout file of Android, we use an imageview control to display an image. If you need to display a check mark on the image, you must implement it in the layout file, so we can only use absolute layout to overlap the two imageviews. This method is obviously not desirable and its adaptive capability is poor!
Here, we can use two methods:
First: Use canvas
Public void first (view v ){
// Prevent immutable bitmap passed to canvas constructor errors
Bitmap bitmap1 = bitmapfactory. decoderesource (getresources (),
R. drawable. Apple). Copy (bitmap. config. argb_8888, true );
Bitmap bitmap2 = (bitmapdrawable) getresources (). getdrawable (
R. drawable. Go). getbitmap ();
Bitmap newbitmap = NULL;
Newbitmap = bitmap. createbitmap (bitmap1 );
Canvas canvas = new canvas (newbitmap );
Paint paint = new paint ();
Int W = bitmap1.getwidth ();
Int H = bitmap1.getheight ();
Int W_2 = bitmap2.getwidth ();
Int H2 = bitmap2.getheight ();
Paint. setcolor (color. Gray );
Paint. setalpha (125 );
Canvas. drawrect (0, 0, bitmap1.getwidth (), bitmap1.getheight (), paint );
Paint = new paint ();
Canvas. drawbitmap (bitmap2, math. Abs (W-W_2)/2,
Math. Abs (H-H2)/2, paint );
Canvas. Save (canvas. all_save_flag );
// Store the newly merged image
Canvas. Restore ();
Image. setimagebitmap (newbitmap );
}
Method 2: Use layerdrawable. The Code is as follows:
Public void second (view v ){
Bitmap bitmap1 = (bitmapdrawable) getresources (). getdrawable (
R. drawable. Apple). getbitmap ();
Bitmap bitmap2 = (bitmapdrawable) getresources (). getdrawable (
R. drawable. Go). getbitmap ();
Drawable [] array = new drawable [2];
Array [0] = new bitmapdrawable (bitmap1 );
Array [1] = new bitmapdrawable (bitmap2 );
Layerdrawable LA = new layerdrawable (array );
// The first parameter is the layer index number, and the following four parameters are left, top, right, and bottom respectively.
La. setlayerinset (0, 0, 0, 0, 0 );
La. setlayerinset (1, 20, 20, 20, 20 );
Image. setimagedrawable (LA );
}