Android实现模仿UCweb菜单效果的方法

2019-12-10 19:59:23刘景俊

item_menu.xml:

 

 
  1. <?xml version="1.0" encoding="utf-8"?>  <RelativeLayout xmlns:android="http://www.easck.com/apk/res/android" 
  2. android:id="@+id/RelativeLayout_Item"  android:layout_width="fill_parent" android:layout_height="wrap_content" 
  3. android:paddingBottom="5dip">  <ImageView android:id="@+id/item_image" 
  4. android:layout_centerHorizontal="true"  android:layout_width="40dip" 
  5. android:layout_height="40dip">  </ImageView> 
  6. <TextView android:layout_below="@id/item_image"  android:id="@+id/item_text" 
  7. android:layout_centerHorizontal="true"  android:layout_width="wrap_content" 
  8. android:layout_height="wrap_content"  style="@style/Text.Location" 
  9. android:text="选项"></TextView>  </RelativeLayout> 

2、用popupwindow作为菜单显示容器:

 

 
  1. View view = this.getLayoutInflater().inflate(R.layout.popwindowdemo, null);  pop = new PopupWindow(view,320,450);//大小设置为全屏幕,这里硬编码的,可修改 
  2. pop.setOutsideTouchable(false);  pop.setBackgroundDrawable(new BitmapDrawable()); 
  3. pop.setFocusable(true);//如果不加这个,Grid不会响应ItemClick  pop.setTouchInterceptor(new OnTouchListener() { 
  4. public boolean onTouch(View v, MotionEvent event) {  // TODO Auto-generated method stub