采用PopupWindow在弹出的菜单右上角实现仿微信。
效果如下面的:
popupWindow代码例如以下:
import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import com.stcyclub.e_community.R;import android.app.Activity;import android.content.Context;import android.graphics.drawable.ColorDrawable;import android.view.LayoutInflater;import android.view.MotionEvent;import android.view.View;import android.view.View.OnClickListener;import android.view.View.OnTouchListener;import android.view.ViewGroup.LayoutParams;import android.widget.ListView;import android.widget.PopupWindow;import android.widget.SimpleAdapter;public class ChangeLifeHallWindow extends PopupWindow { private View mMenuView; public ChangeLifeHallWindow(final Activity context,OnClickListener itemsOnClick) { super(context); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); mMenuView = inflater.inflate(R.layout.change_life_hall_mune, null); ListView life_hall_list = (ListView) mMenuView.findViewById(R.id.life_hall_list); List布局代码例如以下:lts = new ArrayList (); lts.add("aaaaa"); lts.add("bbbb"); lts.add("cccc"); lts.add("sssss"); List
调用代码例如以下:
//调用 ChangeLifeHallWindow mLifeHallWindow = new ChangeLifeHallWindow(RobNewActivity.this, itemsOnClick);mLifeHallWindow.showAtLocation(RobNewActivity.this.findViewById(R.id.base_mune), Gravity.TOP|Gravity.RIGHT, 10, 230); //设置layout在PopupWindow中显示的位置//为弹出窗体实现监听类 private OnClickListener itemsOnClick = new OnClickListener(){ public void onClick(View v) { mLifeHallWindow.dismiss(); } };
版权声明:本文博主原创文章。博客,未经同意不得转载。