Imageview
First, determine the full path of the imageview: Android. widget. imageview.
Description:
Displays any image, sample mark. The imageview class can load images from various sources (such as resources or image libraries). You need to calculate the size of the image, so it can be used in other la S and provide such scaling and coloring (rendering) various display options.
Android: adjustviewbounds
Whether to maintain the aspect ratio. It must be used together with maxwidth and maxheight. Otherwise, it will not work if used separately.
Android: croptopadding
Specifies whether to intercept the specified area and use blank space instead. The setting is ineffective and must be used with scrolly. The effect is as follows. For the implementation code, see the code section:
Android: maxheight
Set the maximum height of the view, which is invalid for separate use and must be used with setadjustviewbounds. If you want to set a fixed image size and keep the image aspect ratio, you need to set it as follows:
1) set setadjustviewbounds to true;
2) Set maxwidth and maxheight;
3) set layout_width and layout_height to wrap_content.
Android: maxwidth
Set the maximum width of the view. Same as above.
Android: scaletype
Set the filling mode of the image.
Android: SRC
Set the drawable (slice or color, but you must specify the size of the view) of the view)
Android: tint
Render the image to a specified color.
Sample Code:
Switch the image when you click the image and darken the other image (mainly used for image transparency)
[Java: nogutter]
View plaincopyprint?
- Package cn.com. chenzheng_java;
- Import Android. App. activity;
- Import Android. content. res. Resources;
- Import Android. Graphics. drawable. drawable;
- Import Android. OS. Bundle;
- Import Android. View. view;
- Import Android. widget. Button;
- Import Android. widget. imageview;
- Import Android. widget. imageview. scaletype;
- /**
- *
- * @ Author chenzheng_java
- *
- */
- Public class imageviewactivity extends activity {
- Private imageview image1;
- Private imageview image2;
- @ Override
- Protected void oncreate (bundle savedinstancestate ){
- Super. oncreate (savedinstancestate );
- Setcontentview (R. layout. imageview );
- Image1 = (imageview) findviewbyid (R. Id. imge1 );
- Image2 = (imageview) findviewbyid (R. Id. imge2 );
- // Resetbutton = (button) findviewbyid (R. Id. resetbutton );
- Final int [] IDs = new int [] {
- R. drawable. red_a,
- R. drawable. blackk,
- R. drawable. Beauty
- };
- Image1.setonclicklistener (New View. onclicklistener (){
- @ Override
- Public void onclick (view v ){
- Int id = IDs [0];
- Image1.setscaletype (scaletype. center); // you can specify the editing mode.
- // Set the background of the imageview. If an image already exists, the background will be overwritten.
- // Image1.setbackgroundresource (ID );
- // Set the image displayed on the imageview
- Image1.setimageresource (ID );
- Image2.setimageresource (R. drawable. Icon );
- Image2.setalpha (100); // sets the transparency. If the value is 255, no transparency is set.
- }
- });
- }
- }
Package cn.com. chenzheng_java; </P> <p> Import android. app. activity; <br/> Import android. content. res. resources; <br/> Import android. graphics. drawable. drawable; <br/> Import android. OS. bundle; <br/> Import android. view. view; <br/> Import android. widget. button; <br/> Import android. widget. imageview; <br/> Import android. widget. imageview. scaletype; <br/>/** <br/> * @ author chenzheng_java <br/> */<br/> public class imageviewactivity extends Activity {</P> <p> private imageview image1; <br/> private imageview image2; <br/> @ override <br/> protected void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. imageview); </P> <p> image1 = (imageview) findviewbyid (R. id. imge1); <br/> image2 = (imageview) findviewbyid (R. id. imge2); <br/> // resetbutton = (button) findviewbyid (R. id. resetbutton); </P> <p> final int [] IDs = new int [] {<br/> r. drawable. red_a, <br/> r. drawable. blackk, <br/> r. drawable. beauty <br/>}; </P> <p> image1.setonclicklistener (new view. onclicklistener () {<br/> @ override <br/> Public void onclick (view v) {<br/> int id = IDs [0]; <br/> image1.setscaletype (scaletype. center); // set the editing mode </P> <p> // set the background of the imageview. If an image already exists, the background will be overwritten <br/> // image1.setbackgroundresource (ID); </P> <p> // set the image displayed on the imageview <br/> image1.setimageresource (ID ); </P> <p> image2.setimageresource (R. drawable. icon); <br/> image2.setalpha (100); // sets the transparency. If the value is 255, no transparency is displayed. </P> <p >}< br/> }); </P> <p >}< br/>
-----------------------------------------------------------
How to Set an image for imageview is as follows:
Three methods to set the image source
Imageview IV;
String filename = "/data/COM. Test/aa.png;
Bitmap Bm = bitmapfactory. decodefile (filename );
Iv. setimagebitmap (BM );
Imageview IV = new imageview (context );
Iv. setimageresource (IV [position]);
Iv. setscaletype (imageview. scaletype. fit_xy );
Iv. setlayoutparams (new gallery. layoutparams (136,88 ));
Mimageview = (imageview) This. findviewbyid (R. Id. myimageview1 );
Mimageview. setimagedrawable (getresources (). getdrawable (R. drawable. Right ));
Imageview
First, determine the full path of the imageview: Android. widget. imageview.
Description:
Displays any image, sample mark. The imageview class can load images from various sources (such as resources or image libraries). You need to calculate the size of the image, so it can be used in other la S and provide such scaling and coloring (rendering) various display options.
Android: adjustviewbounds
Whether to maintain the aspect ratio. It must be used together with maxwidth and maxheight. Otherwise, it will not work if used separately.
Android: croptopadding
Specifies whether to intercept the specified area and use blank space instead. The setting is ineffective and must be used with scrolly. The effect is as follows. For the implementation code, see the code section:
Android: maxheight
Set the maximum height of the view, which is invalid for separate use and must be used with setadjustviewbounds. If you want to set a fixed image size and keep the image aspect ratio, you need to set it as follows:
1) set setadjustviewbounds to true;
2) Set maxwidth and maxheight;
3) set layout_width and layout_height to wrap_content.
Android: maxwidth
Set the maximum width of the view. Same as above.
Android: scaletype
Set the filling mode of the image.
Android: SRC
Set the drawable (slice or color, but you must specify the size of the view) of the view)
Android: tint
Render the image to a specified color.
Sample Code:
Switch the image when you click the image and darken the other image (mainly used for image transparency)
[Java: nogutter]
View plaincopyprint?
- Package cn.com. chenzheng_java;
- Import Android. App. activity;
- Import Android. content. res. Resources;
- Import Android. Graphics. drawable. drawable;
- Import Android. OS. Bundle;
- Import Android. View. view;
- Import Android. widget. Button;
- Import Android. widget. imageview;
- Import Android. widget. imageview. scaletype;
- /**
- *
- * @ Author chenzheng_java
- *
- */
- Public class imageviewactivity extends activity {
- Private imageview image1;
- Private imageview image2;
- @ Override
- Protected void oncreate (bundle savedinstancestate ){
- Super. oncreate (savedinstancestate );
- Setcontentview (R. layout. imageview );
- Image1 = (imageview) findviewbyid (R. Id. imge1 );
- Image2 = (imageview) findviewbyid (R. Id. imge2 );
- // Resetbutton = (button) findviewbyid (R. Id. resetbutton );
- Final int [] IDs = new int [] {
- R. drawable. red_a,
- R. drawable. blackk,
- R. drawable. Beauty
- };
- Image1.setonclicklistener (New View. onclicklistener (){
- @ Override
- Public void onclick (view v ){
- Int id = IDs [0];
- Image1.setscaletype (scaletype. center); // you can specify the editing mode.
- // Set the background of the imageview. If an image already exists, the background will be overwritten.
- // Image1.setbackgroundresource (ID );
- // Set the image displayed on the imageview
- Image1.setimageresource (ID );
- Image2.setimageresource (R. drawable. Icon );
- Image2.setalpha (100); // sets the transparency. If the value is 255, no transparency is set.
- }
- });
- }
- }
Package cn.com. chenzheng_java; </P> <p> Import android. app. activity; <br/> Import android. content. res. resources; <br/> Import android. graphics. drawable. drawable; <br/> Import android. OS. bundle; <br/> Import android. view. view; <br/> Import android. widget. button; <br/> Import android. widget. imageview; <br/> Import android. widget. imageview. scaletype; <br/>/** <br/> * @ author chenzheng_java <br/> */<br/> public class imageviewactivity extends Activity {</P> <p> private imageview image1; <br/> private imageview image2; <br/> @ override <br/> protected void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. imageview); </P> <p> image1 = (imageview) findviewbyid (R. id. imge1); <br/> image2 = (imageview) findviewbyid (R. id. imge2); <br/> // resetbutton = (button) findviewbyid (R. id. resetbutton); </P> <p> final int [] IDs = new int [] {<br/> r. drawable. red_a, <br/> r. drawable. blackk, <br/> r. drawable. beauty <br/>}; </P> <p> image1.setonclicklistener (new view. onclicklistener () {<br/> @ override <br/> Public void onclick (view v) {<br/> int id = IDs [0]; <br/> image1.setscaletype (scaletype. center); // set the editing mode </P> <p> // set the background of the imageview. If an image already exists, the background will be overwritten <br/> // image1.setbackgroundresource (ID); </P> <p> // set the image displayed on the imageview <br/> image1.setimageresource (ID ); </P> <p> image2.setimageresource (R. drawable. icon); <br/> image2.setalpha (100); // sets the transparency. If the value is 255, no transparency is displayed. </P> <p >}< br/> }); </P> <p >}< br/>
-----------------------------------------------------------
How to Set an image for imageview is as follows:
Three methods to set the image source
Imageview IV;
String filename = "/data/COM. Test/aa.png;
Bitmap Bm = bitmapfactory. decodefile (filename );
Iv. setimagebitmap (BM );
Imageview IV = new imageview (context );
Iv. setimageresource (IV [position]);
Iv. setscaletype (imageview. scaletype. fit_xy );
Iv. setlayoutparams (new gallery. layoutparams (136,88 ));
Mimageview = (imageview) This. findviewbyid (R. Id. myimageview1 );
Mimageview. setimagedrawable (getresources (). getdrawable (R. drawable. Right ));