Android Development Note ___ Image View __ Simple screenshot

Source: Internet
Author: User

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 android:orientation= "vertical">6 7     <LinearLayout8         Android:layout_width= "Match_parent"9 Android:layout_height= "300DP"Ten Android:layout_margintop= "10DP" One android:orientation= "Horizontal"> A  -         <TextView -             Android:id= "@+id/tv_capture" the Android:layout_width= "0DP" - Android:layout_height= "Match_parent" - Android:layout_weight= "1" - Android:background= "#ffffff" + Android:textcolor= "#000000" - Android:scrollbars= "vertical" + android:textsize= "17SP" /> A  at         <ImageView -             Android:id= "@+id/iv_capture" - Android:layout_width= "0DP" - Android:layout_height= "Match_parent" - Android:layout_weight= "1" /> -  in     </LinearLayout> -  to     <LinearLayout +         Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content" the Android:layout_margintop= "10DP" * android:orientation= "Horizontal"> $ Panax Notoginseng         <Button -             Android:id= "@+id/btn_chat" the Android:layout_width= "0DP" + Android:layout_height= "Wrap_content" A Android:layout_weight= "1" the Android:text= "Chat" + Android:textcolor= "#000000" - android:textsize= "17SP" /> $  $         <Button -             Android:id= "@+id/btn_capture" - Android:layout_width= "0DP" the Android:layout_height= "Wrap_content" - Android:layout_weight= "1"Wuyi Android:text="" the Android:textcolor= "#000000" - android:textsize= "17SP" /> Wu  -     </LinearLayout> About  $ </LinearLayout>

Java

1  PackageCom.example.alimjan.hello_world;2 3 /**4 * Created by Alimjan on 7/1/2017.5  */6 7 8 ImportAndroid.content.Context;9 Importandroid.content.Intent;Ten ImportAndroid.graphics.Bitmap; One         ImportAndroid.os.Bundle; A         ImportAndroid.os.Handler; -         Importandroid.support.v7.app.AppCompatActivity; - ImportAndroid.text.method.ScrollingMovementMethod; the Importandroid.view.Gravity; - ImportAndroid.view.View; -         ImportAndroid.widget.Button; -         ImportAndroid.widget.ImageView; +         ImportAndroid.widget.TextView; -  +  Public classClass__2_3_3_2extendsAppcompatactivityImplementsView.onclicklistener, View.onlongclicklistener { A     PrivateTextView tv_capture; at     PrivateImageView iv_capture; -  - @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.code_2_3_3_2); inTv_capture =(TextView) Findviewbyid (r.id.tv_capture); -Iv_capture =(ImageView) Findviewbyid (r.id.iv_capture); toTv_capture.setdrawingcacheenabled (true); +Tv_capture.setgravity (gravity.left|gravity.bottom); -Tv_capture.setlines (17); theTv_capture.setmaxlines (17); *Tv_capture.setmovementmethod (NewScrollingmovementmethod ()); $Button Btn_chat =(Button) Findviewbyid (r.id.btn_chat);Panax NotoginsengButton btn_capture =(Button) Findviewbyid (r.id.btn_capture); -Btn_chat.setonclicklistener ( This); theBtn_chat.setonlongclicklistener ( This); +Btn_capture.setonclicklistener ( This); A     } the  +     PrivateString[] Mchatstr = {"Have you eaten yet?" "It's a nice day today." ", -"I won the lottery!" "Let's go see a movie." "What do you do in the evening?" " }; $  $ @Override -      Public BooleanOnlongclick (View v) { -         if(V.getid () = =r.id.btn_chat) { theTv_capture.settext (""); -         }Wuyi         return true; the     } - @Override Wu      Public voidOnClick (View v) { -         if(V.getid () = =r.id.btn_chat) { About             intRandom = (int) (Math.random () *10)% 5; $String newstr = String.Format ("%s\n%s%s", - Tv_capture.gettext (). toString (), Dateutil.getcurdatestr (), Mchatstr[random]); - Tv_capture.settext (NEWSTR); -}Else if(V.getid () = =r.id.btn_capture) { ABitmap Bitmap =Tv_capture.getdrawingcache (); + Iv_capture.setimagebitmap (bitmap); the             //Note that it is not possible to close the drawing cache immediately after completion because the rendering takes time, -             //If you close the cache immediately, the render screen will not find the bitmap object, will be error $             //"Java.lang.IllegalArgumentException:Cannot Draw recycled bitmaps".  theMhandler.postdelayed (Mresetcache, 200); the         } the     } the  -     PrivateHandler Mhandler =NewHandler (); in     PrivateRunnable Mresetcache =NewRunnable () { the @Override the          Public voidrun () { AboutTv_capture.setdrawingcacheenabled (false); theTv_capture.setdrawingcacheenabled (true); the         } the     }; +  -      Public Static voidstarthome (Context mcontext) { theIntent Intent =NewIntent (Mcontext, Class__2_3_3_2.class);Bayi mcontext.startactivity (intent); the     } the}

Android Development Note ___ Image View __ Simple screenshot

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.