当前位置: 代码迷 >> Android >> android 浠?鏂伴椈闃呰?鍣?鑿滃崟寮瑰嚭鏁堟灉锛堥檮婧愮爜DEMO锛?杞
  详细解决方案

android 浠?鏂伴椈闃呰?鍣?鑿滃崟寮瑰嚭鏁堟灉锛堥檮婧愮爜DEMO锛?杞

热度:584   发布时间:2016-04-28 05:02:34.0
android 浠?鏂伴椈闃呰?鍣?鑿滃崟寮瑰嚭鏁堟灉锛堥檮婧愮爜DEMO锛?杞?

杞?浇鑷?http://blog.csdn.net/vipzjyno1/article/details/23872695

寮?鍙戜腑纰板埌闂??涔嬪悗瀹炵幇鐨勶紝瑙夊緱鍙?兘鏈夌殑寮?鍙戣?呯敤鐨勫埌鎴栧垯甯屾湜鐙?珛鎴愪竴涓?皬鍔熻兘DEMO锛屾墍浠ュ氨鏀惧嚭鏉ヨ繖涔堜竴涓狣EMO銆?/span>

鍘熸湰瑙夊緱鏄?渶鍚庡畬鎴愬悗鍙戠綉绔欏?鎴风?鐨勶紝鍙?槸杩欐牱浣撶幇涓嶅嚭涓?涓?姛鑳戒竴涓?姛鑳界殑鍒嗘瀽瀹炵幇鏁堟灉锛岃?屼笖鍛ㄦ湡鏃堕棿闀匡紝鎵?浠ュ氨瀹屾垚涓?閮ㄥ垎锛屽彂涓?閮ㄥ垎锛屾暚璇疯皡瑙c??/span>

涓嬮潰鐨?span style="white-space: pre;">鑿滃崟寮瑰嚭鏁堟灉鍦ㄥ緢澶氱殑鏂伴椈闃呰?鍣ㄤ笂閮芥湁锛屾瘮濡備粖鏃ュご鏉°??60鏂伴椈绛夈?備笅

鍏跺疄杩欎釜瀹炵幇璧锋潵寰堢畝鍗曪紝鐪嬪叾鏁堟灉锛屽叾瀹炲氨鏄?竴涓狿opupWindow锛屼箣鍚庤?瀹氱浉搴攑ostion鐨勬寜閽?偣鍑诲睘鎬э紝涔嬪悗鑾峰彇鎸夐挳鐨勪綅缃?紝缁欏畠璁剧疆鍔ㄧ敾鏄剧ず娑堝け灏卞彲浠ュ嚭鐜颁簡銆?/span>

涓嬮潰鐪嬬湅浠g爜鐨勬?濊矾锛?/span>

鐢变簬鏁翠綋鏄?竴涓狶ISTVIEW锛屾墍浠ユ垜鎶婄偣鍑荤殑浜嬩欢鍐欏埌浜嗗?搴旂殑Adapter閫傞厤鍣ㄤ腑銆?/span>

public class MyAdapter extends BaseAdapter {	LayoutInflater inflater = null;	Activity activity;	ArrayList<News> newslist;	private PopupWindow popupWindow;	public MyAdapter(Activity activity, ArrayList<News> newslist) {		this.activity = activity;		this.newslist = newslist;		inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);		initPopWindow();	}	@Override	public int getCount() {		return newslist != null ? newslist.size() : 0;	}	@Override	public News getItem(int position) {		if (newslist != null && newslist.size() != 0) {			return newslist.get(position);		}		return null;	}	@Override	public long getItemId(int position) {		return position;	}	@Override	public View getView(final int position, View convertView, ViewGroup parent) {		View vi = convertView;		final ViewHolder holder;		if (vi == null) {			vi = inflater.inflate(R.layout.listview_item, null);			holder = new ViewHolder();			holder.item_title = (TextView) vi.findViewById(R.id.item_title);			holder.item_content = (TextView) vi.findViewById(R.id.item_content);			holder.button_showpop = (ImageView) vi.findViewById(R.id.button_showpop);			vi.setTag(holder);		} else {			holder = (ViewHolder) vi.getTag();		}		News news = getItem(position);		holder.item_title.setText(news.getTitle());		holder.item_content.setText(news.getContent());		holder.button_showpop .setOnClickListener(new popAction(position));		return vi;	}	public class ViewHolder {		TextView item_title;		TextView item_content;		ImageView button_showpop;	}		/** 	 * 鍒濆?鍖杙opWindow	 * */	private void initPopWindow() {		View popView = inflater.inflate(R.layout.listview_pop, null);		popupWindow = new PopupWindow(popView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);		popupWindow.setBackgroundDrawable(new ColorDrawable(0));		//璁剧疆popwindow鍑虹幇鍜屾秷澶卞姩鐢?		popupWindow.setAnimationStyle(R.style.PopMenuAnimation);		btn_pop_close = (ImageView) popView.findViewById(R.id.btn_pop_close);	}		/** popWindow 鍏抽棴鎸夐挳 */	private ImageView btn_pop_close;		/** 	 * 鏄剧ずpopWindow	 * */	public void showPop(View parent, int x, int y,int postion) {		//璁剧疆popwindow鏄剧ず浣嶇疆		popupWindow.showAtLocation(parent, 0, x, y);		//鑾峰彇popwindow鐒︾偣		popupWindow.setFocusable(true);		//璁剧疆popwindow濡傛灉鐐瑰嚮澶栭潰鍖哄煙锛屼究鍏抽棴銆?		popupWindow.setOutsideTouchable(true);		popupWindow.update();		if (popupWindow.isShowing()) {					}		btn_pop_close.setOnClickListener(new OnClickListener() {			public void onClick(View paramView) {				popupWindow.dismiss();			}		});	}		/** 	 * 姣忎釜ITEM涓璵ore鎸夐挳瀵瑰簲鐨勭偣鍑诲姩浣?	 * */	public class popAction implements OnClickListener{		int position;		public popAction(int position){			this.position = position;		}		@Override		public void onClick(View v) {			int[] arrayOfInt = new int[2];			//鑾峰彇鐐瑰嚮鎸夐挳鐨勫潗鏍?			v.getLocationOnScreen(arrayOfInt);	        int x = arrayOfInt[0];	        int y = arrayOfInt[1];	        showPop(v, x , y, position);		}	}}

灏辫繖涔堝?鐨勫唴瀹癸紝寰堢畝鍗曪紝鏃ュ悗纰板埌杩欑被鐩稿叧鐨勬晥鏋滐紝涔熷氨涓嶇敤鎬曚簡銆?/span>

涓嬮潰鏄?垜缁忚繃涓婅堪浠g爜瀹炵幇鐨勬晥鏋滐細



涓嬮潰鏀句笂璇ユ晥鏋滄簮鐮丏EMO鐨勪笅杞藉湴鍧?锛?span style="color: #cc0000;">涓嬭浇鍦板潃

  相关解决方案