Description: Eject Popupwindow from the bottom of the screen, with pop-up hidden animation effect. Set the transparency in the background.
For example, the following:
1.mainactivity.java display Popwindow, width and height as the screen size, set a transparency background
public class Mainactivity extends Activity {@Overridepublic void onCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.activity_main); Findviewbyid (R.id.button). SetOnClickListener (New Onclicklistener () {public void OnClick (View v) {Showpopwindow ();}}); private void Showpopwindow () {View parent = ((ViewGroup) This.findviewbyid (Android. r.id.content)). Getchildat (0); View Popview = View.inflate (this, r.layout.camera_pop_menu, null); Button Btncamera = (button) Popview.findviewbyid (R.id.btn_camera_pop_camera); Button Btnalbum = (button) Popview.findviewbyid (r.id.btn_camera_pop_album); Button Btncancel = (button) Popview.findviewbyid (r.id.btn_camera_pop_cancel); int width = Getresources (). Getdisplaymetrics (). Widthpixels;int height = getresources (). Getdisplaymetrics (). Heightpixels;final PopupWindow Popwindow = new Popupwindow (popview,width,height);p Opwindow.setanimationstyle (R.style.animbottom); Popwindow.setfocusable (True);p opwindow.setoutsidetouchable (false);//settings agree to disappear outside click onclicklistener Listener = new Onclicklistener () {public void OnClick (View v) {switch (V.getid ()) {case R. Id.btn_camera_pop_camera:break;case r.id.btn_camera_pop_album:break;case R.id.btn_camera_pop_cancel:break;} Popwindow.dismiss ();}}; Btncamera.setonclicklistener (listener); Btnalbum.setonclicklistener (listener); Btncancel.setonclicklistener ( Listener); Colordrawable DW = new colordrawable (0x30000000);p opwindow.setbackgrounddrawable (DW);p opwindow.showatlocation ( Parent, Gravity.bottom | Gravity.center_horizontal, 0, 0);}}
2.camera_pop_menu.xml Popupwindow loading a layout file
<?XML version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Wrap_content "android:layout_height=" fill_parent "android:orientation=" vertical "& Gt <linearlayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android:lay Out_alignparentbottom= "true" android:layout_margin= "10DP" android:orientation= "vertical" > <but ton android:id= "@+id/btn_camera_pop_camera" style= "@style/txt_camera_pop_menu" Android:la Yout_width= "Match_parent" android:layout_height= "45DP" android:background= "@drawable/pop_first_selec Tor "android:text=" @string/camera_pop_camera "android:textsize=" 18sp "/> <button Android:id= "@+id/btn_camera_pop_album" style= "@style/txt_camera_pop_menu" android:layout_width= "Match_parent" Android:layout_height= "45DP" android:background= "@drawable/pop_last_selector" android:text= "@string/camer A_pop_album "android:textsize=" 18sp "/> <button android:id=" @+id/btn_camera_pop_cancel " style= "@style/txt_camera_pop_menu" android:layout_width= "Match_parent" android:layout_he ight= "45DP" android:layout_margintop= "10DP" android:background= "@drawable/pop_single_selector" android:text= "@string/camera_pop_cancel" android:textsize= "18sp"/> </linearlayout></relat Ivelayout>
Click to download source code
You crossing assume that the article is good, to help a praise it. It's a lift for you, but for me it's the motivation to keep going.
Suppose you want to read our post in the first time. Sweep code follow the public number. Every week not regularly pushes the Android development actual Combat tutorial article, you also wait for what, quickly pay attention to it, learn technology, as CEO. Win white and rich beauty.
。。。
Android开发666 - 安卓开发技术分享 扫描二维码加关注
Popupwindow Bottom Popup