利用PopWindow自定义弹出框

本文介绍了一个自定义的QuickAction菜单实现方案,通过Android中的PopupWindow展示一个带有图标和标题的菜单项列表,支持多种动画效果及自适应显示位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mainActivity:

[java]  view plain copy
  1. package com.cn.nj.quickaction;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.view.View;  
  6. import android.view.View.OnClickListener;  
  7. import android.widget.Button;  
  8.   
  9. import com.cn.nj.quickaction.util.quick.ActionItem;  
  10. import com.cn.nj.quickaction.util.quick.QuickAction;  
  11.   
  12. public class QuickActionTestActivity extends Activity implements OnClickListener{  
  13.       
  14.     private Button button01;  
  15.     /** Called when the activity is first created. */  
  16.     @Override  
  17.     public void onCreate(Bundle savedInstanceState) {  
  18.         super.onCreate(savedInstanceState);  
  19.         setContentView(R.layout.main);  
  20.         button01 = (Button) findViewById(R.id.button1);  
  21.         button01.setOnClickListener(this);  
  22.     }  
  23.     @Override  
  24.     public void onClick(View v) {  
  25.         switch (v.getId()) {  
  26.         case R.id.button1:  
  27.             show(v);  
  28.             break;  
  29.   
  30.         default:  
  31.             break;  
  32.         }  
  33.     }  
  34.       
  35.     private void show(View v){  
  36.         final ActionItem first = new ActionItem();  
  37.         View sexView = v.findViewById(R.id.button1);  
  38.         final QuickAction qa = new QuickAction(sexView);  
  39.         first.setTitle("相机");  
  40.         first.setIcon(getResources().getDrawable(R.drawable.camera_icon_select));  
  41.         first.setOnClickListener(new OnClickListener() {  
  42.             @Override  
  43.             public void onClick(View v) {  
  44.                 getdismiss(qa);  
  45.             }  
  46.         });  
  47.           
  48.           
  49.         final ActionItem second = new ActionItem();  
  50.           
  51.         second.setTitle("文件");  
  52.         second.setIcon(getResources().getDrawable(R.drawable.album_icon_select));  
  53.         second.setOnClickListener(new OnClickListener() {  
  54.             @Override  
  55.             public void onClick(View v) {  
  56.                 getdismiss(qa);  
  57.             }  
  58.         });  
  59.         qa.addActionItem(first);  
  60.         qa.addActionItem(second);  
  61.         qa.show();  
  62.     }  
  63.       
  64.     private void getdismiss(QuickAction qa){  
  65.         qa.dismiss();  
  66.     }  
  67. }  


ActionItem:

[java]  view plain copy
  1. package com.cn.nj.quickaction.util.quick;  
  2.   
  3.   
  4. import android.graphics.drawable.Drawable;  
  5. import android.view.View.OnClickListener;  
  6.   
  7. /** 
  8.  */  
  9. public class ActionItem {  
  10.     private Drawable icon;  
  11.     private String title;  
  12.     private OnClickListener listener;  
  13.       
  14.     /** 
  15.      * Constructor 
  16.      */  
  17.     public ActionItem() {}  
  18.       
  19.     /** 
  20.      * Constructor 
  21.      *  
  22.      * @param icon {@link Drawable} action icon 
  23.      */  
  24.     public ActionItem(Drawable icon) {  
  25.         this.icon = icon;  
  26.     }  
  27.       
  28.     /** 
  29.      * Set action title 
  30.      *  
  31.      * @param title action title 
  32.      */  
  33.     public void setTitle(String title) {  
  34.         this.title = title;  
  35.     }  
  36.       
  37.     /** 
  38.      * Get action title 
  39.      *  
  40.      * @return action title 
  41.      */  
  42.     public String getTitle() {  
  43.         return this.title;  
  44.     }  
  45.       
  46.     /** 
  47.      * Set action icon 
  48.      *  
  49.      * @param icon {@link Drawable} action icon 
  50.      */  
  51.     public void setIcon(Drawable icon) {  
  52.         this.icon = icon;  
  53.     }  
  54.       
  55.     /** 
  56.      * Get action icon 
  57.      * @return  {@link Drawable} action icon 
  58.      */  
  59.     public Drawable getIcon() {  
  60.         return this.icon;  
  61.     }  
  62.       
  63.     /** 
  64.      * Set on click listener 
  65.      *  
  66.      * @param listener on click listener {@link View.OnClickListener} 
  67.      */  
  68.     public void setOnClickListener(OnClickListener listener) {  
  69.         this.listener = listener;  
  70.     }  
  71.       
  72.     /** 
  73.      * Get on click listener 
  74.      *  
  75.      * @return on click listener {@link View.OnClickListener} 
  76.      */  
  77.     public OnClickListener getListener() {  
  78.         return this.listener;  
  79.     }  
  80. }  


QuickAction:

[java]  view plain copy
  1. package com.cn.nj.quickaction.util.quick;  
  2.   
  3.   
  4. import java.util.ArrayList;  
  5.   
  6. import android.content.Context;  
  7. import android.graphics.Rect;  
  8. import android.graphics.drawable.Drawable;  
  9. import android.view.Gravity;  
  10. import android.view.LayoutInflater;  
  11. import android.view.View;  
  12. import android.view.View.OnClickListener;  
  13. import android.view.ViewGroup;  
  14. import android.view.ViewGroup.LayoutParams;  
  15. import android.widget.ImageView;  
  16. import android.widget.LinearLayout;  
  17. import android.widget.ScrollView;  
  18. import android.widget.TextView;  
  19.   
  20. import com.cn.nj.quickaction.R;  
  21.   
  22.   
  23. /** 
  24.  */  
  25. public class QuickAction extends CustomPopupWindow {  
  26.     private final View root;  
  27.     private final ImageView mArrowUp;  
  28.     private final ImageView mArrowDown;  
  29.     private final LayoutInflater inflater;  
  30.     private final Context context;  
  31.       
  32.     protected static final int ANIM_GROW_FROM_LEFT = 1;  
  33.     protected static final int ANIM_GROW_FROM_RIGHT = 2;  
  34.     protected static final int ANIM_GROW_FROM_CENTER = 3;  
  35.     protected static final int ANIM_REFLECT = 4;  
  36.     protected static final int ANIM_AUTO = 5;  
  37.       
  38.     private int animStyle;  
  39.     private ViewGroup mTrack;  
  40.     private ScrollView scroller;  
  41.     private ArrayList<ActionItem> actionList;  
  42.       
  43.     /** 
  44.      * Constructor 
  45.      *  
  46.      * @param anchor {@link View} on where the popup window should be displayed 
  47.      */  
  48.     public QuickAction(View anchor) {  
  49.         super(anchor);  
  50.           
  51.         actionList  = new ArrayList<ActionItem>();  
  52.         context     = anchor.getContext();  
  53.         inflater    = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
  54.           
  55.         root        = (ViewGroup) inflater.inflate(R.layout.quick_popup, null);  
  56.           
  57.         mArrowDown  = (ImageView) root.findViewById(R.id.arrow_down);  
  58.         mArrowUp    = (ImageView) root.findViewById(R.id.arrow_up);  
  59.           
  60.         setContentView(root);  
  61.           
  62.         mTrack          = (ViewGroup) root.findViewById(R.id.tracks);  
  63.         scroller        = (ScrollView) root.findViewById(R.id.scroller);  
  64.         animStyle       = ANIM_AUTO;  
  65.     }  
  66.   
  67.     /** 
  68.      * Set animation style 
  69.      *  
  70.      * @param animStyle animation style, default is set to ANIM_AUTO 
  71.      */  
  72.     public void setAnimStyle(int animStyle) {  
  73.         this.animStyle = animStyle;  
  74.     }  
  75.   
  76.     /** 
  77.      * Add action item 
  78.      *  
  79.      * @param action  {@link ActionItem} object 
  80.      */  
  81.     public void addActionItem(ActionItem action) {  
  82.         actionList.add(action);   
  83.     }  
  84.       
  85.     /** 
  86.      * Show popup window. Popup is automatically positioned, on top or bottom of anchor view. 
  87.      *  
  88.      */  
  89.     public void show () {  
  90.         preShow();  
  91.           
  92.         int xPos, yPos;  
  93.           
  94.         int[] location      = new int[2];  
  95.       
  96.         anchor.getLocationOnScreen(location);  
  97.   
  98.         Rect anchorRect     = new Rect(location[0], location[1], location[0] + anchor.getWidth(), location[1]   
  99.                             + anchor.getHeight());  
  100.   
  101.         createActionList();  
  102.           
  103.         root.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));  
  104.         root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);  
  105.       
  106.         int rootHeight      = root.getMeasuredHeight();  
  107.         int rootWidth       = root.getMeasuredWidth();  
  108.           
  109.         int screenWidth     = windowManager.getDefaultDisplay().getWidth();  
  110.         int screenHeight    = windowManager.getDefaultDisplay().getHeight();  
  111.           
  112.         //automatically get X coord of popup (top left)  
  113.         if ((anchorRect.left + rootWidth) > screenWidth) {  
  114.             xPos = anchorRect.left - (rootWidth-anchor.getWidth());  
  115.         } else {  
  116.             if (anchor.getWidth() > rootWidth) {  
  117.                 xPos = anchorRect.centerX() - (rootWidth/2);  
  118.             } else {  
  119.                 xPos = anchorRect.left;  
  120.             }  
  121.         }  
  122.           
  123.         int dyTop           = anchorRect.top;  
  124.         int dyBottom        = screenHeight - anchorRect.bottom;  
  125.   
  126.         boolean onTop       = (dyTop > dyBottom) ? true : false;  
  127.   
  128.         if (onTop) {  
  129.             if (rootHeight > dyTop) {  
  130.                 yPos            = 15;  
  131.                 LayoutParams l  = scroller.getLayoutParams();  
  132.                 l.height        = dyTop - anchor.getHeight();  
  133.             } else {  
  134.                 yPos = anchorRect.top - rootHeight;  
  135.             }  
  136.         } else {  
  137.             yPos = anchorRect.bottom;  
  138.               
  139.             if (rootHeight > dyBottom) {   
  140.                 LayoutParams l  = scroller.getLayoutParams();  
  141.                 l.height        = dyBottom;  
  142.             }  
  143.         }  
  144.           
  145.         showArrow(((onTop) ? R.id.arrow_down : R.id.arrow_up), anchorRect.centerX()-xPos);  
  146.           
  147.         setAnimationStyle(screenWidth, anchorRect.centerX(), onTop);  
  148.           
  149.         window.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos, yPos);  
  150.     }  
  151.       
  152.     /** 
  153.      * Set animation style 
  154.      *  
  155.      * @param screenWidth screen width 
  156.      * @param requestedX distance from left edge 
  157.      * @param onTop flag to indicate where the popup should be displayed. Set TRUE if displayed on top of anchor view 
  158.      *        and vice versa 
  159.      */  
  160.     private void setAnimationStyle(int screenWidth, int requestedX, boolean onTop) {  
  161.         int arrowPos = requestedX - mArrowUp.getMeasuredWidth()/2;  
  162.   
  163.         switch (animStyle) {  
  164.         case ANIM_GROW_FROM_LEFT:  
  165.             window.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Left : R.style.Animations_PopDownMenu_Left);  
  166.             break;  
  167.                       
  168.         case ANIM_GROW_FROM_RIGHT:  
  169.             window.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Right : R.style.Animations_PopDownMenu_Right);  
  170.             break;  
  171.                       
  172.         case ANIM_GROW_FROM_CENTER:  
  173.             window.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Center : R.style.Animations_PopDownMenu_Center);  
  174.         break;  
  175.               
  176.         case ANIM_REFLECT:  
  177.             window.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Reflect : R.style.Animations_PopDownMenu_Reflect);  
  178.         break;  
  179.           
  180.         case ANIM_AUTO:  
  181.             if (arrowPos <= screenWidth/4) {  
  182.                 window.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Left : R.style.Animations_PopDownMenu_Left);  
  183.             } else if (arrowPos > screenWidth/4 && arrowPos < 3 * (screenWidth/4)) {  
  184.                 window.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Center : R.style.Animations_PopDownMenu_Center);  
  185.             } else {  
  186.                 window.setAnimationStyle((onTop) ? R.style.Animations_PopUpMenu_Right : R.style.Animations_PopDownMenu_Right);  
  187.             }  
  188.                       
  189.             break;  
  190.         }  
  191.     }  
  192.       
  193.     /** 
  194.      * Create action list 
  195.      */  
  196.     private void createActionList() {  
  197.         View view;  
  198.         String title;  
  199.         Drawable icon;  
  200.         OnClickListener listener;  
  201.       
  202.         for (int i = 0; i < actionList.size(); i++) {  
  203.             title       = actionList.get(i).getTitle();  
  204.             icon        = actionList.get(i).getIcon();  
  205.             listener    = actionList.get(i).getListener();  
  206.       
  207.             view        = getActionItem(title, icon, listener);  
  208.           
  209.             view.setFocusable(true);  
  210.             view.setClickable(true);  
  211.                
  212.             mTrack.addView(view);  
  213.         }  
  214.     }  
  215.       
  216.     /** 
  217.      * Get action item {@link View} 
  218.      *  
  219.      * @param title action item title 
  220.      * @param icon {@link Drawable} action item icon 
  221.      * @param listener {@link View.OnClickListener} action item listener 
  222.      * @return action item {@link View} 
  223.      */  
  224.     private View getActionItem(String title, Drawable icon, OnClickListener listener) {  
  225.         LinearLayout container  = (LinearLayout) inflater.inflate(R.layout.action_item, null);  
  226.           
  227.         ImageView img           = (ImageView) container.findViewById(R.id.icon);  
  228.         TextView text           = (TextView) container.findViewById(R.id.title);  
  229.           
  230.         if (icon != null) {  
  231.             img.setImageDrawable(icon);  
  232.         }  
  233.           
  234.         if (title != null) {              
  235.             text.setText(title);  
  236.         }  
  237.           
  238.         if (listener != null) {  
  239.             container.setOnClickListener(listener);  
  240.         }  
  241.   
  242.         return container;  
  243.     }  
  244.       
  245.     /** 
  246.      * Show arrow 
  247.      *  
  248.      * @param whichArrow arrow type resource id 
  249.      * @param requestedX distance from left screen 
  250.      */  
  251.     private void showArrow(int whichArrow, int requestedX) {  
  252.         final View showArrow = (whichArrow == R.id.arrow_up) ? mArrowUp : mArrowDown;  
  253.         final View hideArrow = (whichArrow == R.id.arrow_up) ? mArrowDown : mArrowUp;  
  254.   
  255.         final int arrowWidth = mArrowUp.getMeasuredWidth();  
  256.   
  257.         showArrow.setVisibility(View.VISIBLE);  
  258.           
  259.         ViewGroup.MarginLayoutParams param = (ViewGroup.MarginLayoutParams)showArrow.getLayoutParams();  
  260.          
  261.         param.leftMargin = requestedX - arrowWidth / 2;  
  262.           
  263.         hideArrow.setVisibility(View.INVISIBLE);  
  264.     }  
  265. }  


CustomPopupWindow:

[java]  view plain copy
  1. package com.cn.nj.quickaction.util.quick;  
  2.   
  3.   
  4. import android.content.Context;  
  5. import android.graphics.Rect;  
  6. import android.graphics.drawable.BitmapDrawable;  
  7. import android.graphics.drawable.Drawable;  
  8. import android.view.Gravity;  
  9. import android.view.LayoutInflater;  
  10. import android.view.MotionEvent;  
  11. import android.view.View;  
  12. import android.view.View.OnTouchListener;  
  13. import android.view.ViewGroup.LayoutParams;  
  14. import android.view.WindowManager;  
  15. import android.widget.PopupWindow;  
  16.   
  17. import com.cn.nj.quickaction.R;  
  18.   
  19.   
  20. public class CustomPopupWindow {  
  21.     protected final View anchor;  
  22.     protected final PopupWindow window;  
  23.     private View root;  
  24.     private Drawable background = null;  
  25.     protected final WindowManager windowManager;  
  26.       
  27.     /** 
  28.      * Create a QuickAction 
  29.      *  
  30.      * @param anchor 
  31.      *            the view that the QuickAction will be displaying 'from' 
  32.      */  
  33.     public CustomPopupWindow(View anchor) {  
  34.         this.anchor = anchor;  
  35.         this.window = new PopupWindow(anchor.getContext());  
  36.   
  37.         // when a touch even happens outside of the window  
  38.         // make the window go away  
  39.         window.setTouchInterceptor(new OnTouchListener() {  
  40.             @Override  
  41.             public boolean onTouch(View v, MotionEvent event) {  
  42.                 if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {  
  43.                     CustomPopupWindow.this.window.dismiss();  
  44.                       
  45.                     return true;  
  46.                 }  
  47.                   
  48.                 return false;  
  49.             }  
  50.         });  
  51.   
  52.         windowManager = (WindowManager) anchor.getContext().getSystemService(Context.WINDOW_SERVICE);  
  53.           
  54.         onCreate();  
  55.     }  
  56.   
  57.     /** 
  58.      * Anything you want to have happen when created. Probably should create a view and setup the event listeners on 
  59.      * child views. 
  60.      */  
  61.     protected void onCreate() {}  
  62.   
  63.     /** 
  64.      * In case there is stuff to do right before displaying. 
  65.      */  
  66.     protected void onShow() {}  
  67.   
  68.     protected void preShow() {  
  69.         if (root == null) {  
  70.             throw new IllegalStateException("setContentView was not called with a view to display.");  
  71.         }  
  72.           
  73.         onShow();  
  74.   
  75.         if (background == null) {  
  76.             window.setBackgroundDrawable(new BitmapDrawable());  
  77.         } else {  
  78.             window.setBackgroundDrawable(background);  
  79.         }  
  80.   
  81.         // if using PopupWindow#setBackgroundDrawable this is the only values of the width and hight that make it work  
  82.         // otherwise you need to set the background of the root viewgroup  
  83.         // and set the popupwindow background to an empty BitmapDrawable  
  84.           
  85.         window.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);  
  86.         window.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);  
  87.         window.setTouchable(true);  
  88.         window.setFocusable(true);  
  89.         window.setOutsideTouchable(true);  
  90.   
  91.         window.setContentView(root);  
  92.     }  
  93.   
  94.     public void setBackgroundDrawable(Drawable background) {  
  95.         this.background = background;  
  96.     }  
  97.   
  98.     /** 
  99.      * Sets the content view. Probably should be called from {@link onCreate} 
  100.      *  
  101.      * @param root 
  102.      *            the view the popup will display 
  103.      */  
  104.     public void setContentView(View root) {  
  105.         this.root = root;  
  106.           
  107.         window.setContentView(root);  
  108.     }  
  109.   
  110.     /** 
  111.      * Will inflate and set the view from a resource id 
  112.      *  
  113.      * @param layoutResID 
  114.      */  
  115.     public void setContentView(int layoutResID) {  
  116.         LayoutInflater inflator =  
  117.                 (LayoutInflater) anchor.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
  118.           
  119.         setContentView(inflator.inflate(layoutResID, null));  
  120.     }  
  121.   
  122.     /** 
  123.      * If you want to do anything when {@link dismiss} is called 
  124.      *  
  125.      * @param listener 
  126.      */  
  127.     public void setOnDismissListener(PopupWindow.OnDismissListener listener) {  
  128.         window.setOnDismissListener(listener);  
  129.     }  
  130.   
  131.     /** 
  132.      * Displays like a popdown menu from the anchor view 
  133.      */  
  134.     public void showDropDown() {  
  135.         showDropDown(00);  
  136.     }  
  137.   
  138.     /** 
  139.      * Displays like a popdown menu from the anchor view. 
  140.      *  
  141.      * @param xOffset 
  142.      *            offset in X direction 
  143.      * @param yOffset 
  144.      *            offset in Y direction 
  145.      */  
  146.     public void showDropDown(int xOffset, int yOffset) {  
  147.         preShow();  
  148.   
  149.         window.setAnimationStyle(R.style.Animations_PopDownMenu);  
  150.   
  151.         window.showAsDropDown(anchor, xOffset, yOffset);  
  152.     }  
  153.   
  154.     /** 
  155.      * Displays like a QuickAction from the anchor view. 
  156.      */  
  157.     public void showLikeQuickAction() {  
  158.         showLikeQuickAction(00);  
  159.     }  
  160.   
  161.     /** 
  162.      * Displays like a QuickAction from the anchor view. 
  163.      *  
  164.      * @param xOffset 
  165.      *            offset in the X direction 
  166.      * @param yOffset 
  167.      *            offset in the Y direction 
  168.      */  
  169.     public void showLikeQuickAction(int xOffset, int yOffset) {  
  170.         preShow();  
  171.   
  172.         window.setAnimationStyle(R.style.Animations_PopUpMenu_Center);  
  173.   
  174.         int[] location = new int[2];  
  175.         anchor.getLocationOnScreen(location);  
  176.   
  177.         Rect anchorRect =  
  178.                 new Rect(location[0], location[1], location[0] + anchor.getWidth(), location[1]  
  179.                     + anchor.getHeight());  
  180.   
  181.         root.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));  
  182.         root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);  
  183.           
  184.         int rootWidth       = root.getMeasuredWidth();  
  185.         int rootHeight      = root.getMeasuredHeight();  
  186.   
  187.         int screenWidth     = windowManager.getDefaultDisplay().getWidth();  
  188.         //int screenHeight  = windowManager.getDefaultDisplay().getHeight();  
  189.   
  190.         int xPos            = ((screenWidth - rootWidth) / 2) + xOffset;  
  191.         int yPos            = anchorRect.top - rootHeight + yOffset;  
  192.   
  193.         // display on bottom  
  194.         if (rootHeight > anchorRect.top) {  
  195.             yPos = anchorRect.bottom + yOffset;  
  196.               
  197.             window.setAnimationStyle(R.style.Animations_PopDownMenu_Center);  
  198.         }  
  199.   
  200.         window.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos, yPos);  
  201.     }  
  202.       
  203.     public void dismiss() {  
  204.         window.dismiss();  
  205.     }  
  206. }  


main.xml

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical"  
  6.     android:background="@drawable/bg">  
  7.   
  8.     <Button  
  9.         android:id="@+id/button1"  
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="wrap_content"  
  12.         android:text="@string/btn" />  
  13.   
  14. </LinearLayout>  


action_item.xml

[html]  view plain copy
  1. <LinearLayout  
  2.     xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="horizontal"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="wrap_content"   
  6.     android:clickable="true"  
  7.     android:focusable="true"  
  8.     android:background="@drawable/action_item_btn">  
  9.               
  10.     <ImageView  
  11.         android:id="@+id/icon"   
  12.         android:layout_width="wrap_content"   
  13.         android:layout_height="wrap_content"/>  
  14.   
  15.     <TextView   
  16.         android:id="@+id/title"  
  17.         android:layout_width="fill_parent"   
  18.         android:layout_height="fill_parent"   
  19.         android:gravity="center_vertical"  
  20.         android:paddingLeft="5dip"  
  21.         android:paddingRight="10dip"  
  22.         android:text="Chart"  
  23.         android:textColor="#fff"/>  
  24.                                                
  25. </LinearLayout>           


quick_popup.xml

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout   
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     android:layout_width="wrap_content"  
  5.     android:layout_height="wrap_content">  
  6.           
  7.     <ScrollView   
  8.         android:id="@+id/scroller"  
  9.         android:layout_marginTop="16dip"  
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="wrap_content"  
  12.         android:background="@drawable/quick_popup"  
  13.         android:fadingEdgeLength="5dip"  
  14.         android:scrollbars="none">  
  15.           
  16.         <LinearLayout  
  17.             android:id="@+id/tracks"  
  18.             android:orientation="vertical"  
  19.             android:layout_width="wrap_content"  
  20.             android:layout_height="wrap_content"  
  21.             android:layout_weight="1"  
  22.             android:padding="0dip"/>  
  23.          
  24.     </ScrollView >  
  25.       
  26.     <ImageView  
  27.         android:id="@+id/arrow_up"  
  28.         android:layout_width="wrap_content"  
  29.         android:layout_height="wrap_content"  
  30.         android:src="@drawable/quick_arrow_up" />  
  31.           
  32.     <ImageView  
  33.         android:id="@+id/arrow_down"  
  34.         android:layout_width="wrap_content"  
  35.         android:layout_height="wrap_content"  
  36.         android:layout_below="@id/scroller"  
  37.         android:layout_marginTop="-4dip"  
  38.         android:src="@drawable/quick_arrow_down" />  
  39.   
  40. </RelativeLayout>  


效果图:

 

代码下载地址为:http://download.youkuaiyun.com/detail/niejing654092427/4406118


原文地址:http://blog.youkuaiyun.com/niejing654092427/article/details/7708547

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值