Android實(shí)現(xiàn)底部半透明彈出框PopUpWindow效果
Android底部半透明彈出框PopUpWindow,供大家參考,具體內(nèi)容如下
layout布局:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#66fafafa" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="122dp" android:id="@+id/ll_popupwindow" android:background="#ffffff" android:layout_alignParentBottom="true" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="26dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/popwindow_facebook" android:drawableTop="@mipmap/gif_more_facebook" android:drawablePadding="12dp" android:gravity="center" android:text="Facebook" android:textColor="#4d4d4d" android:textSize="12sp" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/popwindow_whatsapp" android:drawableTop="@mipmap/gif_more_whatsapp" android:drawablePadding="12dp" android:gravity="center" android:text="WhatsApp" android:visibility="gone" android:textColor="#4d4d4d" android:textSize="12sp" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/popwindow_report" android:drawableTop="@mipmap/gif_more_report" android:drawablePadding="12dp" android:gravity="center" android:text="Report" android:textColor="#4d4d4d" android:textSize="12sp" /> </LinearLayout> </LinearLayout> </RelativeLayout>
布局示意:
代碼部分:
/* * 在當(dāng)前頁面調(diào)用initPopUpWindow方法,底部彈出popUpWindow * 重點(diǎn)在popUpWindow的layout最外層布局設(shè)置android:background="#66fafafa" 半透明 * */ private void initPopUpWindow(View root, final String uuid, final String title){ Log.d("click","init popopop"); //inflate得到布局 ,底部彈出框的View final View popView = LayoutInflater.from(mContext).inflate( R.layout.layout_bottom_popwindow, null); View rootView = root; // 當(dāng)前頁面的根布局 //創(chuàng)建popUpWindow對象 寬高占滿頁面 final PopupWindow popupWindow = new PopupWindow(popView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); popupWindow.setTouchable(true); // 設(shè)置彈出動畫 popupWindow.setAnimationStyle(R.style.anim_edit_text_popup); // 顯示在根布局的底部 popupWindow.showAtLocation(rootView, Gravity.BOTTOM | Gravity.LEFT, 0, 0); //點(diǎn)擊底部彈出框之外的部分讓popUpWindow 消失 popView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int height = popView.findViewById(R.id.ll_popupwindow).getTop(); int y=(int) event.getY(); if(event.getAction()==MotionEvent.ACTION_UP){ if(y<height){ popupWindow.dismiss(); } } return true; } }); //彈出框中控件的點(diǎn)擊事件 TextView share_facebook= (TextView) popView.findViewById(R.id.popwindow_facebook); share_facebook.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { share_facebook(uuid,title); popupWindow.dismiss(); } }); final TextView share_whatsApp= (TextView) popView.findViewById(R.id.popwindow_whatsapp); boolean whatsappFound = CheckUtils.isAppInstalled(mContext, "com.whatsapp"); if (whatsappFound) { share_whatsApp.setVisibility(View.VISIBLE); share_whatsApp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { share_whatsapp(uuid,title); } }); } TextView report= (TextView) popView.findViewById(R.id.popwindow_report); report.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(mContext, ReportActivity.class); intent.putExtra("fromch", true); intent.putExtra("tid", uuid); mContext.startActivity(intent); popupWindow.dismiss();<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="100" android:fromYDelta="0.0" android:toYDelta="100%" /> </set> } }); }
動畫部分
進(jìn)入時從最下方彈出到最上方
消失時從最上方向下移動直到隱藏
<style name="anim_edit_text_popup"> <item name="android:windowEnterAnimation">@anim/popup_in</item> <item name="android:windowExitAnimation">@anim/popup_out</item> </style>
popup_in:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="100" android:fromYDelta="100.0%" android:toYDelta="0.0" /> </set>
pop_out:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="100" android:fromYDelta="0.0" android:toYDelta="100%" /> </set>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android 解決ScrollView嵌套CridView顯示問題
這篇文章主要介紹了Android 解決ScrollView嵌套CridView顯示問題的相關(guān)資料,使用ScrollView嵌套CridView的時候會出現(xiàn)顯示不全的問題,這里提供解決辦法,需要的朋友可以參考下2017-08-08Android使用Item Swipemenulistview實(shí)現(xiàn)仿QQ側(cè)滑刪除功能
大家都用過QQ,肯定有人好奇QQ滑動刪除Item的效果是怎樣實(shí)現(xiàn)的,其實(shí)我們使用Swipemenulistview就可以簡單的實(shí)現(xiàn)。這篇文章主要介紹了Android使用ItemSwipemenulistview實(shí)現(xiàn)仿QQ側(cè)滑刪除功能,需要的朋友可以參考下2017-02-02Android編程實(shí)現(xiàn)對話框形式進(jìn)度條功能示例
這篇文章主要介紹了Android編程實(shí)現(xiàn)對話框形式進(jìn)度條功能,結(jié)合具體實(shí)例形式分析了Android對話框形式進(jìn)度條的功能與布局相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-09-09android 限制某個操作每天只能操作指定的次數(shù)(示例代碼詳解)
這篇文章主要介紹了android 限制某個操作每天只能操作指定的次數(shù),本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-06-06Android編程獲取網(wǎng)絡(luò)連接方式及判斷手機(jī)卡所屬運(yùn)營商的方法
這篇文章主要介紹了Android編程獲取網(wǎng)絡(luò)連接方式及判斷手機(jī)卡所屬運(yùn)營商的方法,涉及Android針對網(wǎng)絡(luò)的判斷及本機(jī)信息的獲取技巧,需要的朋友可以參考下2016-01-01