1.:
2. Core code:
Package Com.example.pic_reflection;import Android.app.activity;import Android.graphics.bitmap;import Android.graphics.bitmap.config;import Android.graphics.canvas;import Android.graphics.lineargradient;import Android.graphics.matrix;import Android.graphics.paint;import Android.graphics.porterduff.mode;import Android.graphics.porterduffxfermode;import Android.graphics.shader.tilemode;import Android.graphics.drawable.bitmapdrawable;import Android.os.bundle;import Android.widget.imageview;public Class Mainactivity extends Activity {private ImageView img = null; Private ImageView orginalimg; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); This.orginalimg = (ImageView) This.findviewbyid (r.id.img); This.orginalImg.setBackgroundResource (r.drawable.b); This.img = (ImageView) This.findviewbyid (R.id.reflection1); This.img.setImageBitmap (Createreflectedimage (((Bitmapdrawable) this.getresources (). getdrawable (r.drawable.b)). Getbitmap (), 110); } public static Bitmap createreflectedimage (Bitmap originalimage, int reflectionheight) {int width = Originalim Age.getwidth (); int height = originalimage.getheight (); Matrix matrix = new Matrix (); Achieve picture rollover 90 degrees Matrix.prescale (1,-1); if (reflectionheight > Height) reflectionheight = height; Create a reflection picture (half the size of the original picture) Bitmap Reflectionimage = Bitmap.createbitmap (originalimage, 0, Height-reflectionheight, wid Th, Reflectionheight, Matrix, false); Create a reflection image Bitmap Finalreflection = Bitmap.createbitmap (width, reflectionheight, config.argb_8888); Create canvas canvases canvas = new canvas (finalreflection); Canvas.drawbitmap (originalimage, 0, 0, NULL); Draw the reflection picture onto the canvas canvas.drawbitmap (reflectionimage, 0, 0, NULL); Paint Shaderpaint = new paint (); Create a linear gradient LinearGradient object lineArgradient shader = new LinearGradient (0, 0, 0, finalreflection.getheight () + 1, 0x70ffffff, 0X00FFFFFF, Tilemode.mirror); Shaderpaint.setshader (shader); Shaderpaint.setxfermode (New Porterduffxfermode (mode.dst_in)); The image is reflected when the canvas is reversed, and the gradient is added to the image's size area. Canvas.drawrect (0, 0, Width, finalreflection.getheight (), shaderpaint); return finalreflection; }}3, Main.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" wrap_content " android:layout_height=" wrap_content " android:o rientation= "vertical" > <include layout= "@layout/activity_main"/> <imageview android:id= "@+id/reflection1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content"/></ Linearlayout>
4, Activity_main.xml
<?xml version= "1.0" encoding= "Utf-8"? ><framelayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" wrap_content " android:layout_height=" wrap_content "> < ImageView android:id= "@+id/img" android:layout_width= "match_parent" android:layout_height= "Match_ Parent " android:scaletype=" Fitxy "/> <textview android:id=" @+id/lblbanner " android:layout _width= "Match_parent" android:layout_height= "wrap_content" android:layout_gravity= "Bottom " Android:background= "#88000000" android:ellipsize= "End" android:gravity= "Center_horizontal|center_ Vertical " android:singleline=" true " android:text=" car One " android:textcolor=" #FFF "/></ Framelayout>