android 模仿uc標簽頁,模仿UCweb菜單 - 白羽雕弓 - 博客園

UCWeb的菜單看起來不錯,自己想模仿做一個,苦惱一直沒有思路

google了幾天,終于找到一個帖子? http://www.eoeandroid.com/viewthread.php?tid=28824

按照上面提供的思路實現了

1、保留menu按鍵作用

2、用popupwindow作為菜單顯示容器

3、用GridView顯示所有子菜單

代碼

1、布局文件

popupwindow.xml

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:background="#50000000"

android:layout_height="fill_parent"

android:gravity="bottom|center_horizontal">

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="320dip"

android:background="@drawable/bkg2"

android:id="@+id/popdialog"

android:layout_height="250dip"

android:gravity="center_vertical|center_horizontal"

>

android:id="@+id/gridview"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:numColumns="4"

android:verticalSpacing="10dip"

android:horizontalSpacing="10dip"

android:stretchMode="columnWidth"

android:gravity="center"

/>

item_menu.xml

android:id="@+id/RelativeLayout_Item"

android:layout_width="fill_parent" android:layout_height="wrap_content"

android:paddingBottom="5dip">

android:layout_centerHorizontal="true"

android:layout_width="40dip"

android:layout_height="40dip">

android:id="@+id/item_text"

android:layout_centerHorizontal="true"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

style="@style/Text.Location"

android:text="選項">

2、用popupwindow作為菜單顯示容器

View view = this.getLayoutInflater().inflate(R.layout.popwindowdemo, null);

pop = new PopupWindow(view,320,450);//大小設置為全屏幕,這里硬編碼的,可修改

pop.setOutsideTouchable(false);

pop.setBackgroundDrawable(new BitmapDrawable());

pop.setFocusable(true);//如果不加這個,Grid不會響應ItemClick

pop.setTouchInterceptor(new OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {

// TODO Auto-generated method stub

if (event.getY()<240){ //這里處理,當點擊gridview以外區域的時候,菜單關閉

if (pop.isShowing())

pop.dismiss();

}

Log.d("Demo", "popupWindow::onTouch >>> view: "

+ v + ", event: " + event);

return false;

}

});

3、初始化gridview

/** 菜單圖片 **/

int[] menu_image_array = { R.drawable.menu_search,

R.drawable.menu_filemanager, R.drawable.menu_downmanager,

R.drawable.menu_fullscreen, R.drawable.menu_inputurl,

R.drawable.menu_bookmark, R.drawable.menu_bookmark_sync_import,

R.drawable.menu_sharepage, R.drawable.menu_quit,

R.drawable.menu_nightmode, R.drawable.menu_refresh,

R.drawable.menu_more };

/** 菜單文字 **/

String[] menu_name_array = { "搜索", "文件管理", "下載管理", "全屏", "網址", "書簽",

"加入書簽", "分享頁面", "退出", "夜間模式", "刷新", "更多" };

/**

* 構造菜單Adapter

*

* @param menuNameArray

* 名稱

* @param imageResourceArray

* 圖片

* @return SimpleAdapter

*/

private SimpleAdapter getMenuAdapter(String[] menuNameArray,

int[] imageResourceArray) {

ArrayList> data = new ArrayList>();

for (int i = 0; i < menuNameArray.length; i++) {

HashMap map = new HashMap();

map.put("itemImage", imageResourceArray[i]);

map.put("itemText", menuNameArray[i]);

data.add(map);

}

SimpleAdapter simperAdapter = new SimpleAdapter(this, data,

R.layout.item_menu, new String[] { "itemImage", "itemText" },

new int[] { R.id.item_image, R.id.item_text });

return simperAdapter;

}

menuGrid = (GridView) view.findViewById(R.id.gridview);

menuGrid.setAdapter(getMenuAdapter(menu_name_array, menu_image_array));

4、注冊Menu彈起事件

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// TODO Auto-generated method stub

pop.showAtLocation(findViewById(R.id.mainfrm), Gravity.CENTER|Gravity.BOTTOM, 0, 0);

return false;//super.onCreateOptionsMenu(menu);

}

5、注冊menu子菜單單擊事件

menuGrid.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView> arg0, View arg1, int arg2,

long arg3) {

Log.v("Demo", "menuGrid.setOnItemClickListener: "+arg2+" "+arg3);

Toast.makeText(UIMenu.this, "Click"+arg2, Toast.LENGTH_SHORT).show();

if (pop.isShowing()) //關閉菜單

pop.dismiss();

}

});

6、界面截圖

5246762_1.png

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542376.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542376.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542376.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ipv6路由協議配置_IPV6尋址,標頭和路由協議

ipv6路由協議配置The IPV6 address is 128 bits. Whereas IPV4 is represented by 4 groups of decimal numbers, same IPV6 is represented by 8 groups of hexadecimal numbers. The example of IPV6 address is 2001:0db8:85a3:0000:0000:8a2e:0370:7334. IPV6地址是128位。…

rpc框架

Motan&#xff0c;dubbo轉載于:https://www.cnblogs.com/zhangshiwen/p/5980886.html

android webview 監聽js,Android webview與js的數據交互

項目要用到Webview和js交互&#xff0c;查了查以前的項目感覺還是有必要整理下的。簡單描述下項目中用到的地方&#xff0c;比如說在web頁需要用到登錄的地方點擊登錄跳轉到APP原生登錄界面去登錄&#xff0c;點擊web頁的撥打電話彈出原生dialog詢問是否撥打&#xff0c;點擊we…

c ++查找字符串_C ++異常處理| 查找輸出程序| 套裝1

c 查找字符串Program 1: 程序1&#xff1a; #include <iostream>using namespace std;int main(){try {int num1 10;int num2 0;int res 0;res num1 / num2;}catch (exception e) {cout << "Exception: Divide By Zero" << endl;}return 0;}O…

python的repr和str有什么不同_str()和repr()的異同

str()函數和repr()函數&#xff0c;都是Python內置的標準函數。這兩個函數都是根據參數對象返回一個字符串&#xff0c;但是又有一些不一樣的地方。我們在使用的時候&#xff0c;常常搞混&#xff0c;傾向于使用簡單明了的str()函數&#xff0c;而搞不清楚為什么還有一個不知所…

android web通訊錄,Android手機開發之通訊錄

Android手機開發——通訊錄實現增加、查詢、修改、刪除的功能&#xff0c;輸入聯系人信息&#xff0c;點擊“添加”按鈕&#xff0c;可以添加聯系人信息到數據庫&#xff1b;點擊“查詢”按鈕&#xff0c;會發現添加的聯系人信息顯示在界面中&#xff1b;重新輸入聯系人電話&am…

有關UITableView--cell復用問題

近來用Tableview做了一個九宮格。過程中碰到了兩個cell復用問題。 問題一&#xff1a; 在cell中為button添加addTarget點擊事件時&#xff0c;出現后面的cell會重疊它前面cell的事件。代碼如下&#xff1a; C代碼 static NSString *CellWithIdentifier "DiscoverHomeTab…

python客戶端和服務端實驗_結合服務器和客戶端python

我正在嘗試使用python(稍后可能用c語言)和TCP套接字制作一個本地網絡聊天程序。我的目的是讓服務器監聽當前計算機的地址以獲取傳入消息&#xff0c;并將這些消息轉發給客戶端(我現在還不確定)。客戶端將是一個簡單的gui&#xff0c;可以通過本地連接向活動服務器發送消息。實際…

python常用語法和示例_C語言切換案例教程,語法,示例和規則

python常用語法和示例使用默認情況下的決策 (Decision making using switch-case-default) Many times in our daily lives, we face conditions where we are required to choose between a number of alternatives rather than just two or three. For example, which school…

android so abi適配,Android NDK學習(六): so文件兼容之abiFilters的使用

最近項目中遇到了要使用JavaCV的情況&#xff0c;涉及到了abi兼容的選擇。因為如果全部都適配的話&#xff0c;包很大&#xff0c;這樣兼容那些用戶數極少的cpu就很不劃算&#xff0c;所以我只適配了armeabi-v7a這一個。但是今天在x64-v8a的模擬器上看的時候&#xff0c;提示我…

python中doc=parased.getroot()_python中執行sed命令操作源文件時出現錯誤

我想在python中執行一個sed命令&#xff0c;第一種方法直接指定文件時&#xff0c;可以正確輸出結果&#xff0c;但是第二種我打開文件操作的時候就有問題&#xff0c;不知道什么原因&#xff0c;求高手解答&#xff1f;(1)>>> sedcmd"sed -n \s/{//g; p\ /qye/p…

JavaScript基礎之Number對象和Math對象

2019獨角獸企業重金招聘Python工程師標準>>> //Math對象//屬性float Math.E; //返回自然對數的底數e&#xff0c;約2.718float Math.LN2; //返回2的自然對數&#xff0c;約0.693float Math.LN10; //返回10的自然對數&#xff0c;約2.302fl…

c++ stl 獲取最小值_如何在C ++ STL中找到向量的最小/最小元素?

c stl 獲取最小值Given a vector and we have to minimum/smallest element using C STL program. 給定一個向量&#xff0c;我們必須使用C STL程序最小/最小元素。 尋找向量的最小元素 (Finding smallest element of a vector) To find a smallest or minimum element of a …

android studio panic,Android Studio模擬器PANIC錯誤

Android Studio模擬器突然停止工作.當我嘗試運行虛擬設備時,我在事件日志中收到以下錯誤.模擬器:PANIC:找不到AVD系統路徑.請定義ANDROID_SDK_ROOT仿真器:處理完成,退出代碼為1所以我檢查了ANDROID_SDK_ROOT環境變量設置的值,它是空的.所以我把它設置為/Users/{username}/Libra…

linux特殊權限之訪問權限

特殊權限如/etc/passwd:sSuid:普通用戶以管理員身份運行命令&#xff08;chmod us FILE、chmod u-s FILE&#xff09;如果FILE本身原來就有執行權限&#xff0c;SUID顯示為s&#xff1b;否則顯示SSgid:基本組以管理組身份運行命令&#xff08;chmod gs FILE、chmod g-s FILE&am…

vb.net變量值變化觸發事件_Angular變化檢測的理解

獲取臟檢查的時機Angular 使用NgZone獲取變化的通知&#xff0c;然后進行全面的變化檢測&#xff0c;進而更新Dom臟檢查的過程Angular的數據流是自頂而下&#xff0c;從父組件到子組件單項流動&#xff0c;單項數據流保證了高效可預測的變化檢測。盡管檢查了父組件之后&#xf…

python 算術右移_Python算術序列| 競爭編碼問題

python 算術右移Question: 題&#xff1a; In mathematics, when in an arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant then it is called arithmetic constant. 在數學中&#xff0c;當在算術序列中是…

Android8內測申請,小米 6 安卓 8.0 來了 內測開始招募

Android 8.0 已經正式發布多時&#xff0c;目前不少廠商已經啟動了旗下進行的 Android 8.0 適配計劃。但令人納悶的是&#xff0c;一向對系統升級比較熱心的小米卻遲遲沒有動靜。好消息是&#xff0c;此前網友曝光的消息顯示&#xff0c;MIUI 已經悄然在官方論壇中招募小米 6 的…

My linux

為什么80%的碼農都做不了架構師&#xff1f;>>> 1.linux 命令方式修改機器名稱 # hostname newHostName # vi /etc/sysconfig/network 修改或增加配置&#xff1a;hostnamenewHostName # vi /etc/hosts 修改對應的本地HOST映射 xx.xxx.xxx.xxx newHostName 2.Redha…

狂神說es筆記_人教版七上英語Unit5電子課本音頻+課堂筆記+課后同步習題

1人教 七上英語Unit5單詞七年級英語上冊Unit 5單詞默寫1做&#xff1b;干(助動詞)__________2做&#xff0c;干(助動詞第三人稱單數形式)__________3有__________4網球__________5球__________6乒乓球______7球棒&#xff1b;球拍__________8(英式)足球____________________9排…