1. 程式人生 > >常用控制元件(一):PopWindow ,提示框,陰影線

常用控制元件(一):PopWindow ,提示框,陰影線

彈出popwindow

private void initListView() {
		listView = new ListView(this);
		listView.setBackgroundResource(R.drawable.listview_background); //設定listView 背景
		listView.setDivider(null);	//設定條目之間的分隔線為null
		listView.setVerticalScrollBarEnabled(false); // 關閉
		
		listView.setAdapter(new MyListAdapter());
	}


downArrow.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				System.out.println("=======");
				//定義 popupWindow
				popWin = new PopupWindow(MainActivity.this);
				popWin.setWidth(input.getWidth()); //設定寬度
				popWin.setHeight(200);	//設定popWin 高度
				
				popWin.setContentView(listView); //為popWindow填充內容
				popWin.setOutsideTouchable(true); // 點選popWin 以處的區域,自動關閉 popWin
				
				popWin.showAsDropDown(input, 0, 0);//設定 彈出視窗,顯示的位置
				
			}
		});
進度提示框
public void showProgressBar(String message) {
if (progressDialog != null && progressDialog.isShowing()) {
return;
}
// progressDialog.setMessage(message);
progressDialog.setCancelable(true);
progressDialog.setCanceledOnTouchOutside(true);// 點選進度條以外的部分也鎖屏
progressDialog.show();
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.pg, null);
Window window = progressDialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
// 設定透明度為0.3
lp.alpha = 1.0f;
lp.dimAmount = 0.0f;
lp.gravity = Gravity.CENTER;
window.setAttributes(lp);
window.setContentView(v);
progressDialog.setOnKeyListener(MyKeyListener);
}

public void stopWaitBar() {
if (progressDialog != null) {
progressDialog.dismiss();
}
} 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical" >
    <ProgressBar 
        style="@android:style/Widget.ProgressBar.Large.Inverse"
        android:layout_width="30dip"
        android:layout_height="30dip"
        />
</LinearLayout>


線:

<TextView android:layout_width="fill_parent"
  android:id="@id/xct_lthj_page_query_mainframe_line_up"
  android:layout_height="@dimen/xct_lthj_space_zeroone" />
 <TextView android:layout_width="fill_parent"
  android:id="@id/xct_lthj_page_query_mainframe_line_down"
  android:layout_height="@dimen/xct_lthj_space_zeroone" />


--------------------------------------------------------------------------------------------------

彈出一個popwindow :

點選 外部可以消失

點選返回鍵可以消失

/**
     * 圖片上傳popupwindow
     */
    public static class MyPopupWindow extends PopupWindow {

        public MyPopupWindow(Context mContext, View parent) {

            View view = View.inflate(mContext, R.layout.activity_giftmoney_share_popwindow, null);
            view.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.fade_ins));
            LinearLayout ll_popup = (LinearLayout) view.findViewById(R.id.line_popup);
            ll_popup.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.push_bottom));
            // 設定寬高
            setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
            setHeight(400);
            //設定一個預設背景圖
            setBackgroundDrawable(new BitmapDrawable());
            //設定外部可以點選關閉
            setOutsideTouchable(true);
            //設定點選返回鍵可以關閉
            setFocusable(true);
            //設定佈局檔案
            setContentView(view);
            TextView takpe_tv = (TextView) view.findViewById(R.id.takpe_tv);
            TextView select_tv = (TextView) view.findViewById(R.id.select_tv);
            TextView btn_cancel = (TextView) view.findViewById(R.id.btn_cancel);
            takpe_tv.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    weixin();
                    dismiss();
                }
            });
            select_tv.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    phone();
                    dismiss();
                }
            });
            btn_cancel.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    dismiss();
                }
            });
        }

        public void weixin() {
        }

        

        public void phone() {
        }

        // 點選外部關閉
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋體';font-size:11.3pt;">view.setOnClickListener(<span style="color:#cc7832;">new </span>View.OnClickListener() {
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋體';font-size:11.3pt;">    <span style="color:#bbb529;">@Override
</span>
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋體';font-size:11.3pt;"><span style="color:#bbb529;">    </span><span style="color:#cc7832;">public void </span><span style="color:#ffc66d;">onClick</span>(View v) {
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋體';font-size:11.3pt;">        dismiss()<span style="color:#cc7832;">;
</span>
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋體';font-size:11.3pt;"><span style="color:#cc7832;">    </span>}
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋體';font-size:11.3pt;">})<span style="color:#cc7832;">;</span>
    }


onclick:

new MyPopupWindow(this, recyclerview).showAtLocation(this.getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
recyclerview 引數沒用