泡泡窗口(二)

来源:互联网 发布:单农男装网络旗舰店 编辑:程序博客网 时间:2024/04/20 11:59

不和任何控件结合。纯生态 是上一篇博客的扩展 这个方法使用起来更加方便
定义一个MainActivity.java 中的内部类

public class SelectPopuWindow extends PopupWindow {        private Context context;        private int ReuestCode;        public SelectPopuWindow(Context mContext, View parent,                final int requestCode) {            this.ReuestCode = requestCode;            this.context = mContext;            View view = View                    .inflate(mContext, R.layout.item_popupwindows, null);            view.startAnimation(AnimationUtils.loadAnimation(mContext,                    R.anim.fade_ins));            LinearLayout ll_popup = (LinearLayout) view                    .findViewById(R.id.ll_popup);            ll_popup.startAnimation(AnimationUtils.loadAnimation(mContext,                    R.anim.push_bottom_in_2));            setWidth(LayoutParams.FILL_PARENT);            setHeight(LayoutParams.FILL_PARENT);            setBackgroundDrawable(new BitmapDrawable());            setFocusable(true);            setOutsideTouchable(true);            setContentView(view);            showAtLocation(parent, Gravity.BOTTOM, 0, 0);            update();            Button bt1 = (Button) view                    .findViewById(R.id.item_popupwindows_camera);            Button bt2 = (Button) view                    .findViewById(R.id.item_popupwindows_Photo);            Button bt3 = (Button) view                    .findViewById(R.id.item_popupwindows_cancel);            bt1.setOnClickListener(new OnClickListener() {                @Override                public void onClick(View v) {                Toast.makeText(WriteMoodActivity.this, "1", Toast.LENGTH_LONG).show();            });            bt2.setOnClickListener(new OnClickListener() {                @Override                public void onClick(View v) {    Toast.makeText(WriteMoodActivity.this, "2", Toast.LENGTH_LONG).show();                    }                    dismiss();                }            });            bt3.setOnClickListener(new OnClickListener() {                @Override                public void onClick(View v) {                    Toast.makeText(WriteMoodActivity.this, "23", Toast.LENGTH_LONG).show();                }            });        }    }

泡泡窗口的布局是写在activity_main.xml 文件中的

<LinearLayout        android:id="@+id/ll_popup"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_alignParentBottom="true"        android:background="#ffffff"        android:orientation="vertical" >        <TextView            android:layout_width="match_parent"            android:layout_height="1dp"            android:background="#ff495a" />        <LinearLayout            android:layout_width="match_parent"            android:layout_height="55dp"            android:orientation="horizontal" >            <Button                android:id="@+id/item_popupwindows_camera"                android:layout_width="match_parent"                android:layout_height="55dp"                android:background="@drawable/bt_nobgd"                android:textColor="#585858"                android:textSize="18sp"                android:text="拍照" />        </LinearLayout>

关于动画方面我就不粘大家可以看上一篇博客

0 0
原创粉丝点击