Android Popupwindow display location and display size

Source: Internet
Author: User


<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    android: Background= "#DA4F30"    android:cachecolorhint= "#000000"    android:orientation= "vertical" >    < ListView        android:id= "@+id/lv_dialog"        android:layout_width= "match_parent"        android:layout_height= " Match_parent "        android:cachecolorhint=" #00000000 "        android:scrollbars=" None "        android:o Verscrollmode= "Never" >    </ListView></LinearLayout>

Package Com.example.showpop;import Android.app.activity;import Android.content.context;import Android.graphics.drawable.bitmapdrawable;import Android.os.bundle;import Android.view.gravity;import Android.view.layoutinflater;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.window;import Android.view.windowmanager;import Android.widget.adapterview;import Android.widget.adapterview.onitemclicklistener;import Android.widget.arrayadapter;import Android.widget.imageview;import Android.widget.linearlayout;import Android.widget.listview;import Android.widget.popupwindow;public class Mainactivity extends Activity {private LinearLayout layout;private ListView Listview;private Popupwindow popupwindow;private String title[] = {"1", "2", "3", "4", "5"};p rivate ImageView ImageView ; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (Window.feature_no_title); Setcontentview (r.layout.activity_main); IMageview= (ImageView) Findviewbyid (R.id.imageview_above_more); Imageview.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View v) {Showpopupwindow (ImageView);}}); public void Showpopupwindow (View parent) {//Load layout layouts = (linearlayout) layoutinflater.from (mainactivity.this). Inflate (r.layout.dialog, NULL);//Find layout control in ListView = (ListView) Layout.findviewbyid (R.id.lv_dialog);// Set Adapter Listview.setadapter (New arrayadapter<string> (Mainactivity.this,r.layout.text, R.id.tv_text, title));// Instantiate Popupwindowpopupwindow = new Popupwindow (layout, 300,500);//Controls whether the keyboard can get focus popupwindow.setfocusable (TRUE);// Sets the background popupwindow.setbackgrounddrawable of the Popupwindow popup form (new bitmapdrawable (null, "")); WindowManager manager= (WindowManager) Getsystemservice (Context.window_service); @SuppressWarnings ("deprecation")/ /Get Xoffint Xpos=manager.getdefaultdisplay (). GetWidth ()/2-popupwindow.getwidth ()/2;//xoff,yoff offsets based on the lower left corner of the anchor. Popupwindow.showasdropdown (parent,xpos, 0);//monitor Listview.setonitemclicklistener (nEW Onitemclicklistener () {@Overridepublic void Onitemclick (adapterview<?> arg0, View arg1, int arg2,long arg3) {//Off Closed Popupwindowpopupwindow.dismiss ();p Opupwindow = null;}});}}
Source Code

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.