編輯:關於Android編程
本文實例分析了Android開發中PopupWindow用法。分享給大家供大家參考,具體如下:
private TextView tv_appmanager_title; private ListView lv_app_manager; private LinearLayout ll_appmanager_loading; private AppManagerProvider provider; private List<AppManagerInfo> infos ; private AppManagerAdapter adapter; private PopupWindow localPopupWindow; private Handler handler = new Handler(){ public void handleMessage(android.os.Message msg) { switch (msg.what) { case Constants.MSG_APP_MANAGER: ll_appmanager_loading.setVisibility(View.INVISIBLE); adapter = new AppManagerAdapter(infos, AppManagerActivity.this); lv_app_manager.setAdapter(adapter); break; } }; }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.appmanager); lv_app_manager = (ListView) this.findViewById(R.id.lv_app_manager); ll_appmanager_loading = (LinearLayout) this.findViewById(R.id.ll_appmanager_loading); ll_appmanager_loading.setVisibility(View.VISIBLE); new Thread(){ public void run() { provider = new AppManagerProvider(AppManagerActivity.this); infos = provider.getAppManagerInfo(); Message msg = new Message(); msg.what = Constants.MSG_APP_MANAGER; handler.sendMessage(msg); }; }.start(); lv_app_manager.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if(null != localPopupWindow){ localPopupWindow.dismiss(); localPopupWindow = null; } int [] location = new int[2]; view.getLocationInWindow(location); int x = location[0] + 60; int y = location[1]; TextView tv = new TextView(AppManagerActivity.this); AppManagerInfo info = (AppManagerInfo) lv_app_manager.getItemAtPosition(position); tv.setText(info.getPackName()); tv.setTextSize(20); tv.setTextColor(Color.RED); localPopupWindow = new PopupWindow(tv, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); Drawable background = new ColorDrawable(Color.GRAY); localPopupWindow.setBackgroundDrawable(background); localPopupWindow.showAtLocation(tv, 51, x, y); } }); lv_app_manager.setOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if(null != localPopupWindow){ localPopupWindow.dismiss(); localPopupWindow = null; } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if(null != localPopupWindow){ localPopupWindow.dismiss(); localPopupWindow = null; } } }); }
更多關於Android相關內容感興趣的讀者可查看本站專題:《Android開發入門與進階教程》、《Android通信方式總結》、《Android基本組件用法總結》、《Android視圖View技巧總結》、《Android布局layout技巧總結》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
先看一看我的代碼運行結果。代碼運行起來初始化狀態: 點擊開始按鈕,唱片機的機械臂勻速接近唱片磁盤,同時唱片磁盤也開始勻速順時針旋轉: &n
1. 產品概述 友盟社會化組件,可以讓移動應用快速具備社會化分享、登錄、評論、喜歡等功能,並提供實時、全面的社會化數據統計分析服務。 指南將會手把手教你使用社
廢話不多說,先上效果圖在下載的時候藍色的邊會跟著下載的進度以前變化--思路:大概的思路就是在這張圖片上蓋上一層視圖,視圖裡面有畫兩個圓,內圓是顯示加載進度的,顯示的顏色是
在android開發中ListView是比較常用的組件,它以列表的形式展示具體內容,並且能夠根據數據的長度自適應顯示。抽空把對ListView的使用做了整理,並寫了個小例