Android popupWindow彈出窗體實(shí)現(xiàn)方法分析
本文實(shí)例講述了Android popupWindow彈出窗體實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
1. 建立popupwindow顯示的布局頁面(普通的view任意布局)
<?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="80dip"
android:background="@drawable/popup_yellow_window_bg"
android:orientation="horizontal" >
<TextView
android:id="@+id/popupwindow_app_uninstall_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:drawableTop="@drawable/kn_malware_scan_deep_click"
android:text="卸 載"/>
</LinearLayout>
2. activity中布局加載以及填充,建立popupwindow對象,設(shè)置相應(yīng)參數(shù)或?qū)傩?/p>
View contentView = View.inflate(getApplicationContext(), R.layout.popup_window, null); LinearLayout ll_uninstall = (LinearLayout) contentView.findViewById(R.id.ll_uninstall); //設(shè)置popupwindow內(nèi)布局組件的監(jiān)聽(與其他組件相似) MyOnClickListener l = new MyOnClickListener(position); ll_uninstall.setOnClickListener(l); PopupWindow mPopupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.WRAP_CONTENT, 70); int[] arrayOfInt = new int[2]; view.getLocationInWindow(arrayOfInt); int x = arrayOfInt[0] + 60; int y = arrayOfInt[1]; //1 指定popupwindow的背景 2 popupwindow能夠獲得焦點(diǎn) mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); mPopupWindow.setFocusable(true); mPopupWindow.showAtLocation(view, Gravity.LEFT|Gravity.TOP, x, y); //在合適位置取消popupwindow顯示 mPopupWindow.dismiss();
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android窗口相關(guān)操作技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
相關(guān)文章
Textvie實(shí)現(xiàn)左邊圖片和換行文字左對齊的方法
下面小編就為大家分享一篇Textvie實(shí)現(xiàn)左邊圖片和換行文字左對齊的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01
android中SwipeRefresh實(shí)現(xiàn)各種上拉,下拉刷新示例
這篇文章主要介紹了android中SwipeRefresh實(shí)現(xiàn)各種上拉,下拉刷新示例,非常具有實(shí)用價值,需要的朋友可以參考下。2017-03-03
Android應(yīng)用開發(fā)中模擬按下HOME鍵的效果(實(shí)現(xiàn)代碼)
Android應(yīng)用開發(fā)中, 有一種場景,就是我們不希望用戶直接按Back鍵退出Activity,而是希望應(yīng)用隱藏到后臺,類似于按Home鍵的效果2013-05-05
Android使用SoundPool實(shí)現(xiàn)播放音效
這篇文章主要為大家詳細(xì)介紹了Android使用SoundPool實(shí)現(xiàn)播放音效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-11-11
Android編程實(shí)現(xiàn)將壓縮數(shù)據(jù)庫文件拷貝到安裝目錄的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)將壓縮數(shù)據(jù)庫文件拷貝到安裝目錄的方法,涉及Android處理壓縮文件的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10
android中強(qiáng)制更新app實(shí)例代碼
本篇文章主要介紹了android中強(qiáng)制更新app實(shí)例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-05-05

