Android Demo---Implemented from the bottom pop-up window

Source: Internet
Author: User

In the previous blog post, the small part of the simple introduction of how to make a round corner of the button and rounded pictures, with the keyboard and the dance between the fingers, ushered in a new problem, do not know if the small partners have such experience, to the app as an example, click on the Avatar, will pop up from the bottom of a window, from the album to , click the corresponding button to complete the corresponding operation, in the process of small part of the project encountered a similar problem, small series after some tinkering, finally took care of ING, today this article, small Bovin Boven simple Introduction, how to click on the avatar, realize the story from the bottom pop-up window, the story realized is pop-up sliding window, The main use is to set the activity of the style to achieve the pop-up effect and sliding effect.

First, the first step is to write the XML code as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" wrap_content "android:gravity=" Center_horizont Al "android:orientation=" vertical "><linearlayout android:id=" @+id/pop_layout "android:layout_width=" fill_p    Arent "android:layout_height=" wrap_content "android:gravity=" center_horizontal "android:orientation=" vertical " Android:layout_alignparentbottom= "true" android:background= "@drawable/btn_style_alert_dialog_background" > &L T Button android:id= "@+id/btn_take_photo" android:layout_marginleft= "20dip" android:layout_marginright= "20dip" android:layout_margintop= "20dip" android:layout_width= "fill_parent" android:layout_height= "WR Ap_content "android:text=" photo "android:background=" @drawable/btn_style_alert_dialog_button "Android:te xtstyle= "Bold"/> <Button android:id= "@+id/btn_pick_photo" android:layout_marginleft= "20dip" android:layout_marginright= "20dip" android:layout_margintop= "5dip" android:layout_width= "fill_parent" android:layout_height= "WR Ap_content "Android:text=" from the album select "android:background=" @drawable/btn_style_alert_dialog_button "Android : textstyle= "bold"/> <button android:id= "@+id/btn_cancel" android:layout_marginleft= "20dip" Android oid:layout_marginright= "20dip" android:layout_margintop= "15dip" android:layout_marginbottom= "15dip" and Roid:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:text= "Cancel" Android:backgroun d= "@drawable/btn_style_alert_dialog_cancel" android:textcolor= "#ffffff" android:textstyle= "bold"/></line Arlayout></relativelayout>
The second step, new Java class, named Selectpicpopupwindow, inherit the activity class and implement the Onclicklistener interface, this interface can not be implemented, the specific code is as follows: 
Package Com.h8.imageroundcorner;import Android.app.activity;import Android.os.bundle;import Android.view.motionevent;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.linearlayout;import Android.widget.toast;public Class Selectpicpopupwindow extends Activity implements Onclicklistener{private Button Btn_take_photo, Btn_pick_photo, Btn_ Cancel;private linearlayout layout; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.alert_dialog); Btn_take_photo = (Button) This.findviewbyid (R.id.btn_ Take_photo) Btn_pick_photo = (Button) This.findviewbyid (r.id.btn_pick_photo); btn_cancel = (Button) This.findviewbyid (R.id.btn_cancel); layout= (LinearLayout) Findviewbyid (r.id.pop_layout);//Add Selection window range listener to get the contact first, i.e. no more ontouchevent () function, click anywhere else to execute the ontouchevent () function to destroy Activitylayout.setonclicklistener (new Onclicklistener () {public void OnClick (View v) { TODO Auto-generated Method StuBtoast.maketext (Getapplicationcontext (), "Hint: Click outside the window to close the window!" ", Toast.length_short). Show ();}}); /Add button to monitor btn_cancel.setonclicklistener (this); Btn_pick_photo.setonclicklistener (this); Btn_take_ Photo.setonclicklistener (this);} Implement Ontouchevent touch screen function But destroy this activity @Overridepublic a Boolean ontouchevent (Motionevent event) {finish (); return true;} public void OnClick (View v) {switch (V.getid ()) {R.id.btn_take_photo:break;case r.id.btn_pick_photo:break;case R.id.btn_cancel:break;default:break;} Finish ();}}
Third, write the Mainactivity class, click on the avatar, let her slide from the bottom of a certain popup box, the code is as follows:  
Package Com.h8.imageroundcorner;import Android.app.activity;import Android.content.intent;import Android.graphics.bitmap;import Android.graphics.bitmapfactory;import Android.graphics.canvas;import Android.graphics.paint;import Android.graphics.porterduffxfermode;import Android.graphics.rect;import Android.graphics.rectf;import Android.graphics.bitmap.config;import Android.graphics.porterduff.mode;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.imageview;import Android.widget.textview;public class Testactivity extends Activity {ImageView ImageView; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.test); ImageView = (ImageView) Findviewbyid (R.ID.IMAGEVIEW2); Bitmap B = Bitmapfactory.decoderesource (Getresources (), r.drawable.my); Imageview.setimagebitmap (ToRoundCorner (b),      200)); To add the text control to the listener, click the popup Definition window Imageview.setonclicklistener (new Onclicklistener () {Public void OnClick (View v) {startactivity (new Intent (Testactivity.this,selectpicpopupwindow.class));});} public static Bitmap Toroundcorner (Bitmap Bitmap, int pixels) {Bitmap output = Bitmap.createbitmap (Bitmap.getwidth (), Bit Map.getheight (), config.argb_8888); Canvas canvas = new canvas (output), final int color = 0xff424242;final Paint paint = new paint (); final rect rect = new rect (0, 0, bitmap.getwidth (), Bitmap.getheight ()), final RECTF RECTF = new RECTF (rect); final float roundpx = Pixels;paint.setan Tialias (True); Canvas.drawargb (0, 0, 0, 0);p aint.setcolor (color); Canvas.drawroundrect (RECTF, ROUNDPX, ROUNDPX, paint) ;p Aint.setxfermode (New Porterduffxfermode (mode.src_in)); Canvas.drawbitmap (bitmap, rect, rect, paint); return output;}}
Fourth Step, set the property style to achieve the effect we need, the code is as follows:

<resources> <!--Base application theme, dependent on API level.    This theme are replaced by Appbasetheme from Res/values-vxx/styles.xml on newer devices. --<style name= "Appbasetheme" parent= "Android:Theme.Light" > <!--Theme customizations av Ailable in newer API levels can go in res/values-vxx/styles.xml, while customizations related to BAC        Kward-compatibility can go here. -</style> <!--application theme.  --<style name= "Apptheme" parent= "Appbasetheme" > <!--all customizations that is not specific to a Particular api-level can go here. -</style> <style name= "Animbottom" parent= "@android: Style/animation" > <item name= "and Roid:windowenteranimation "> @anim/push_bottom_in</item> <item name=" Android:windowexitanimation ">@ anim/push_bottom_out</item> </style> <style name= "mydialogstYlebottom "parent=" Android:Theme.Dialog "> <item name=" Android:windowanimationstyle "> @style/animbottom </item> <item name= "Android:windowframe" > @null </item> <!--border--<item name= "and Roid:windowisfloating ">true</item> <!--is on the activity--<item name=" Android:windowistransluce NT ">true</item> <!--Translucent--<item name=" Android:windownotitle ">true</item> <!--Untitled        --<item name= "Android:windowbackground" > @android:color/transparent</item> <!--background Transparent-- <item name= "android:backgrounddimenabled" >true</item> <!--Blur-to-</style></resources&gt ;
Fifth Step, when you click on the avatar, we need her to slide into the style of the effect, click Cancel when you need her to slide out of the effect, how to achieve NIE, the specific code as shown, the first is the effect of sliding into the type:

<?xml version= "1.0" encoding= "Utf-8"?>  <!--up and down--  <set xmlns:android= "/http Schemas.android.com/apk/res/android ">        <translate          android:duration=" Android:fromydelta= "          100%p "          android:toydelta=" 0 "/>        </set>  
Next, the slide-out effect code looks like this:

<?xml version= "1.0" encoding= "Utf-8"?>  <!--up and down--  <set xmlns:android= "/http Schemas.android.com/apk/res/android ">              <translate          android:duration=" Android:fromydelta= "          0 "          android:toydelta=" 50%p "/>  </set>
Finally, let's look at the effect of the run, as shown in:


Small Series of words: The main article is a simple description of how to slide out of the bottom of the pop-up box, hoping to help the needs of the small partners, each time to achieve a simple effect, small series will be particularly happy, accompanied by the pace of practice, small series slowly grow Up ' (*∩_∩*), This is the meaning of life , or that sentence for small, is not only a challenge is an opportunity, because the knowledge is the same, in addition, in the small part of the process of life, leaving the most precious memories, although the later small not necessarily engaged in the Android industry, code World, a lot of things, some sweet, some warm, some tactfully into a song , some stretches endlessly, in these stories, our only common place is, a certain year, a certain month, some placid day, once very much loves you! Love You-the days of this internship, Android brought to the small series of various surprises.     

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Demo---Implemented from the bottom pop-up window

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.