This article illustrates how Android implements the effect of imitating ucweb menus. Share to everyone for your reference. Specifically as follows:
UCWeb's menu looks good, imitate to do one, the idea realizes as follows:
1. Keep Menu key function
2, using Popupwindow as a menu display container
3, with the GridView display all submenus
The code is as follows:
1, Layout file:
Popupwindow.xml:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout 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" >
<linearlayout
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 "
>
<gridview
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"
/>
</LinearLayout>
</LinearLayout>
Item_menu.xml:
<?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=" fill_parent "Android:layout_" height= "Wrap_content"
android:paddingbottom= "5dip" >
<imageview android:id= "@+id/item_image"
Android:layout_centerhorizontal= "true"
android:layout_width= "40dip"
android:layout_height= "40dip" >
</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"
style= "@style/text.location"
android:text= "Options" ></TextView>
</ Relativelayout>
2, using Popupwindow as a menu display container:
View view = This.getlayoutinflater (). Inflate (R.layout.popwindowdemo, null);
Pop = new Popupwindow (view,320,450);//size set to full screen, hard-coded here, can modify
pop.setoutsidetouchable (false);
Pop.setbackgrounddrawable (New bitmapdrawable ());
Pop.setfocusable (TRUE);/If you do not add this, the grid does not respond to ItemClick
pop.settouchinterceptor (New Ontouchlistener () {public
Boolean Ontouch (View V, motionevent event) {
//TODO auto-generated method Stub
if (Event.gety () <240) {//here processed, When clicking outside the GridView area, the menu closes
if (pop.isshowing ())
Pop.dismiss ();
LOG.D ("Demo", "Popupwindow::ontouch >>> View:"
+ V + ", Event:" + event);
return false;
}
});
3, initialization of the GridView:
/** menu Picture **/int[] Menu_image_array = {r.drawable.menu_search, R.drawable.menu_filemanager, R.drawable.menu_downmanag Er, 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.dr
Awable.menu_more}; /** Menu Text **/string[] Menu_name_array = {"Search", "File Management", "Download Management", "full Screen", "url", "Bookmark", "Add Bookmark", "Share Page", "Exit", "Night Mode", "Refresh", "more
" }; /** * Construction Menu Adapter * * @param menunamearray * name * @param imageresourcearray * picture * @return Simpleadapter/Private S Impleadapter Getmenuadapter (string[] Menunamearray, int[] imageresourcearray) {arraylist
4. Register Menu Bounce Event:
@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, Register menu submenu Click event:
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 ())//Close menu
Pop.dismiss ();
}
});
6, Screen screen:
I hope this article will help you with your Android program.