成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Android如何實(shí)現(xiàn)uc瀏覽器一樣的菜單

移動(dòng)開(kāi)發(fā) Android
菜單開(kāi)發(fā)也是程序員經(jīng)常需要關(guān)注的,如何使菜單變得更加方便用戶使用是每一個(gè)開(kāi)發(fā)者都要面臨的實(shí)際問(wèn)題,今天給Android開(kāi)發(fā)者介紹一下如何開(kāi)發(fā)出像UC瀏覽器一樣的菜單。使用AlertDialog生成菜單,利用setView()方法設(shè)置菜單視圖。

菜單開(kāi)發(fā)也是程序員經(jīng)常需要關(guān)注的,如何使菜單變得更加方便用戶使用是每一個(gè)開(kāi)發(fā)者都要面臨的實(shí)際問(wèn)題,今天給Android開(kāi)發(fā)者介紹一下如何開(kāi)發(fā)出像UC瀏覽器一樣的菜單。使用AlertDialog生成菜單,利用setView()方法設(shè)置菜單視圖。

布局如下:

1、菜單布局

利用GridView

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width
="wrap_content" android:layout_height="wrap_content"  
    android:orientation
="vertical">  
    
<GridView android:id="@+id/menu"  
        android:layout_width
="fill_parent"  
        android:layout_height
="fill_parent"  
        android:numColumns
="2"  
         android:verticalSpacing
="5dip"  
         android:horizontalSpacing
="5dip"  
         android:stretchMode
="columnWidth"  
         android:gravity
="center"></GridView>  
</LinearLayout>  

2、每一個(gè)item的布局

<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:id
="@+id/RelativeLayout_Item" android:layout_width="wrap_content"  
    android:layout_height
="wrap_content" android:paddingBottom="5dip">  
    
<ImageView android:id="@+id/item_image"  
        android:layout_centerHorizontal
="true" android:layout_width="wrap_content"  
        android:layout_height
="wrap_content"></ImageView>  
    
<TextView android:layout_below="@id/item_image" android:id="@+id/item_text"  
        android:layout_centerHorizontal
="true" android:layout_width="wrap_content"  
        android:layout_height
="wrap_content" android:text="選項(xiàng)"></TextView>  
</RelativeLayout>  

主程序代碼如下:

代碼比較簡(jiǎn)單,注釋非常詳細(xì)

package com.cloay.down.utils;  
  
import java.util.ArrayList;  
import java.util.HashMap;  
  
import com.cloay.down.R;  
  
import android.app.AlertDialog;  
import android.content.Context;  
import android.view.View;  
import android.widget.AdapterView;  
import android.widget.AdapterView.OnItemClickListener;  
import android.widget.GridView;  
import android.widget.SimpleAdapter;  
/** 
* 菜單工具類(lèi) 
* MenuUtil.java 
* @author cloay 
* 2011-10-25 
*/  
public class MenuUtil {  
    
private static AlertDialog menuDialog;// menu菜單Dialog  
    
private static GridView menuGrid;  
      
    
/** 菜單圖片 **/  
    static 
int[] menu_image_array = { R.drawable.menu_open_in_background, R.drawable.menu_redownload, R.drawable.menu_detail, R.drawable.menu_delete };  
    
/** 菜單文字 **/  
    static 
String[] menu_name_array = { "打開(kāi)""重新下載""詳細(xì)""刪除"};  
    
public static void ShowMenuDialog(final Context context){  
        View menuView 
= View.inflate(context, R.layout.menu, null);  
        menuDialog 
= new AlertDialog.Builder(context)  
        .setView(menuView)  
        .create();  
        menuDialog.show();  
        menuGrid  
= (GridView) menuView.findViewById(R.id.menu);  
        menuGrid.setAdapter(getMenuAdapter(context, menu_name_array, menu_image_array));  
        menuGrid.setOnItemClickListener(
new OnItemClickListener() {  
            
//監(jiān)聽(tīng)menu按鈕事件  
            @Override  
            
public void onItemClick(AdapterView<?> parent, View view,  
                    
int position, long id) {  
                switch(position){  
                
case 0:     //open file  
                      
                    break;  
                
case 1:     //redownload 重新下載  
                      
                    break;  
                
case 2:     //file details    
                      
                    break;  
                
case 3:     //delete file  
                      
                    break;  
                }  
            }  
        });  
    }  
      
    
/** 
     
* 為menuGrid設(shè)置Adapter 
     
* @param context 
     
* @param menuNameArray 
     
* @param imageResourceArray 
     
* @return 
     
*/  
    
private static SimpleAdapter getMenuAdapter(Context context, String[] menuNameArray,  
            
int[] imageResourceArray) {  
        ArrayList
<HashMap<StringObject>> data = new ArrayList<HashMap<StringObject>>();  
        
for (int i = 0; i < menuNameArray.length; i++) {  
            HashMap
<StringObject> map = new HashMap<StringObject>();  
            map.put(
"itemImage", imageResourceArray[i]);  
            map.put(
"itemText", menuNameArray[i]);  
            data.add(map);  
        }  
        SimpleAdapter simperAdapter 
= new SimpleAdapter(context, data,  
                R.layout.item_menu, 
new String[] { "itemImage""itemText" },  
                
new int[] { R.id.item_image, R.id.item_text });  
        return simperAdapter;  
    }  
}  
責(zé)任編輯:景琦 來(lái)源: Android
相關(guān)推薦

2012-03-20 11:07:08

2015-09-01 17:09:41

uc瀏覽器源碼

2011-12-08 15:40:16

UC瀏覽器

2017-03-22 20:30:40

2021-06-04 15:55:32

瀏覽器UC瀏覽器安卓手機(jī)

2021-01-28 07:06:55

Microsoft Edge瀏覽器 Dev 開(kāi)發(fā)

2010-09-18 17:07:13

2013-12-24 14:57:22

android模擬器

2020-02-04 17:11:21

Chrome瀏覽器UC瀏覽器

2020-02-05 10:59:49

瀏覽器ChromeUC瀏覽器

2014-01-13 11:09:42

UC瀏覽器PC智能電視

2013-01-17 14:55:49

2010-04-05 21:57:14

Netscape瀏覽器

2013-11-18 14:42:53

瀏覽器渲染

2012-03-20 11:41:18

海豚瀏覽器

2012-03-20 11:31:58

移動(dòng)瀏覽器

2012-03-19 17:25:22

2013-06-28 15:27:44

2010-08-10 09:40:23

Flex與瀏覽器交互
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: xx视频在线观看 | 久久久综合 | 日本粉嫩一区二区三区视频 | 黑人巨大精品欧美一区二区免费 | 91大神新作在线观看 | 性色在线 | 国产日韩欧美一区 | 免费国产视频在线观看 | 精品久久中文字幕 | 有码一区| 91天堂网| 成人网av | 国产精品激情在线 | 性国产xxxx乳高跟 | 中文字幕一区二区三区在线乱码 | 国产毛片久久久 | 午夜视频网站 | 欧美色性 | 免费一区在线观看 | 一区二区三区四区在线视频 | 美女视频久久 | 久久精品99久久 | 亚洲国产成人精品女人久久久 | 动漫www.被爆羞羞av44 | 激情综合五月 | 久久国产一区二区 | 国产激情在线 | 国产午夜精品一区二区三区四区 | 99国产在线| 国产精品久久久久久久久久久久午夜片 | 一区二区三区中文字幕 | 成人精品国产一区二区4080 | 国产玖玖 | 日韩在线精品 | 天天色综| 免费亚洲成人 | 色综合一区 | 久久国产日韩欧美 | 毛片在线免费 | 国产精品欧美一区二区三区不卡 | 91在线视频一区 |