国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android中自定義PopupWindow實現彈出框并帶有動畫效果

2019-12-12 05:09:24
字體:
來源:轉載
供稿:網友

使用PopupWindow來實現彈出框,并且帶有動畫效果

首先自定義PopupWindow

public class LostPopupWindow extends PopupWindow {public Lost lost;public void onLost(Lost lost){this.lost = lost;}private View conentView;public View getConentView() {return conentView;}public LostPopupWindow(final Activity context) {LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);conentView = inflater.inflate(R.layout.lost_pop_menu, null);int h = context.getWindowManager().getDefaultDisplay().getHeight();int w = context.getWindowManager().getDefaultDisplay().getWidth();// 設置SelectPicPopupWindow的Viewthis.setContentView(conentView);// 設置SelectPicPopupWindow彈出窗體的寬this.setWidth(w / 2 + 50);// 設置SelectPicPopupWindow彈出窗體的高this.setHeight(LayoutParams.WRAP_CONTENT);// 設置SelectPicPopupWindow彈出窗體可點擊this.setFocusable(true);this.setOutsideTouchable(true);// 刷新狀態this.update();// 實例化一個ColorDrawable顏色為半透明ColorDrawable dw = new ColorDrawable(0000000000);// 點back鍵和其他地方使其消失,設置了這個才能觸發OnDismisslistener ,設置其他控件變化等操作this.setBackgroundDrawable(dw);// mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);// 設置SelectPicPopupWindow彈出窗體動畫效果this.setAnimationStyle(R.style.AnimationPreview);LinearLayout send = (LinearLayout) conentView.findViewById(R.id.send);LinearLayout mySend = (LinearLayout) conentView.findViewById(R.id.my_send);LinearLayout all = (LinearLayout) conentView.findViewById(R.id.all);send.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {LostPopupWindow.this.dismiss();lost.onLost(2);}});mySend.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {LostPopupWindow.this.dismiss();lost.onLost(1);}});all.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {LostPopupWindow.this.dismiss();lost.onLost(0);}});}/*** 顯示popupWindow** @param parent*/public void showPopupWindow(View parent) {if (!this.isShowing()) {// 以下拉方式顯示popupwindowthis.showAsDropDown(parent, parent.getLayoutParams().width / 2, 18);} else {this.dismiss();}}}

R.layout.lost_pop_menu文件

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="200dp"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:background="@drawable/black_menu_pop_bg"android:orientation="vertical"android:paddingLeft="@dimen/activity_horizontal_margin"><LinearLayoutandroid:id="@+id/send"android:layout_width="match_parent"android:layout_height="40dp"android:gravity="center_vertical"android:orientation="horizontal"android:scaleType="fitXY"><ImageViewandroid:id="@+id/img5"android:layout_width="20dp"android:layout_height="20dp"android:src="@drawable/icon_lost_add" /><TextViewandroid:id="@+id/item_content"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:text="發布信息"android:textColor="#e5e5e6"android:textSize="18sp" /></LinearLayout><Viewandroid:layout_width="match_parent"android:layout_height="1px"android:background="#616467" /><LinearLayoutandroid:id="@+id/my_send"android:layout_width="match_parent"android:layout_height="40dp"android:gravity="center_vertical"android:orientation="horizontal"><ImageViewandroid:id="@+id/img6"android:layout_width="20dp"android:layout_height="20dp"android:scaleType="fitXY"android:src="@drawable/icon_lost_my" /><TextViewandroid:id="@+id/item_content1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:text="我發布的信息"android:textColor="#e5e5e6"android:textSize="18sp" /></LinearLayout><Viewandroid:layout_width="match_parent"android:layout_height="1px"android:background="#616467" /><LinearLayoutandroid:id="@+id/all"android:layout_width="match_parent"android:layout_height="40dp"android:gravity="center_vertical"android:orientation="horizontal"><ImageViewandroid:id="@+id/img7"android:layout_width="20dp"android:layout_height="20dp"android:scaleType="fitXY"android:src="@drawable/icon_all" /><TextViewandroid:id="@+id/item_content2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:text="全部信息"android:textColor="#e5e5e6"android:textSize="18sp" /></LinearLayout></LinearLayout>動畫R.style.AnimationPreview<style name="AnimationPreview"><item name="android:windowEnterAnimation">@anim/fade_in</item><item name="android:windowExitAnimation">@anim/fade_out</item></style>@anim/fade_in<?xml version="1.0" encoding="utf-8"?><!-- 左上角擴大--><scale xmlns:android="http://schemas.android.com/apk/res/android"android:interpolator="@android:anim/accelerate_decelerate_interpolator"android:fromXScale="0.001"android:toXScale="1.0"android:fromYScale="0.001"android:toYScale="1.0"android:pivotX="100%"android:pivotY="10%"android:duration="200" />@anim/fade_out<!-- 左上角縮小 --><scale xmlns:android="http://schemas.android.com/apk/res/android"android:interpolator="@android:anim/accelerate_decelerate_interpolator"android:fromXScale="1.0"android:toXScale="0.001"android:fromYScale="1.0"android:toYScale="0.001"android:pivotX="100%"android:pivotY="10%"android:duration="200" />

接下來就是使用了

LostPopupWindow popWindow = new LostPopupWindow(ZiXunDetailActivity.this);((ImageView)(popWindow.getConentView().findViewById(R.id.img5))).setImageResource(R.drawable.ckplico);((ImageView)(popWindow.getConentView().findViewById(R.id.img6))).setImageResource(R.drawable.fbplico);((ImageView)(popWindow.getConentView().findViewById(R.id.img7))).setImageResource(R.drawable.zfplico);((TextView)(popWindow.getConentView().findViewById(R.id.item_content))).setText("查看評論");((TextView)(popWindow.getConentView().findViewById(R.id.item_content1))).setText("發表評論");((TextView)(popWindow.getConentView().findViewById(R.id.item_content2))).setText("轉發文章");popWindow.showPopupWindow(linMain);popWindow.onLost(new Lost() {@Overridepublic void onLost(int index) {switch (index){case 0: //轉發文章break;case 1: //發表評論lineFooter.setVisibility(View.VISIBLE);break;case 2://查看評論Bundle bundle=new Bundle();bundle.putString("id",mID);startActivity(PingLunActivity.class, "熱門評論", bundle);break;}}});

效果圖

以上所述是小編給大家介紹的Android中自定義PopupWindow實現彈出框并帶有動畫效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嘉鱼县| 宽甸| 平乡县| 临澧县| 西昌市| 潞西市| 莱西市| 衡东县| 仁布县| 徐闻县| 海盐县| 驻马店市| 方城县| 肇庆市| 苗栗县| 宜良县| 宽甸| 珠海市| 大化| 东兰县| 湘阴县| 西林县| 五峰| 教育| 杨浦区| 木兰县| 邢台市| 武定县| 洛阳市| 崇礼县| 灵丘县| 临武县| 镶黄旗| 汪清县| 平利县| 泗洪县| 长武县| 文安县| 韶关市| 扶沟县| 湖南省|