Android 為應用增加可移動的懸浮視窗
需求描述:
在使用手機客戶端瀏覽內嵌網頁的時候,介面出現一個懸浮的重新整理按鈕,點選網頁重新載入。
佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/float_fresh"
android:padding="5dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/icon_fresh"
android:background="@drawable/bg_floatbutton"/>
</LinearLayout>

設定視窗型別在所有視窗之上:
這裡說一下這個LayoutParams.TYPE_PHONE。我們看一下官方文件說明:
These are non-application windows providing user interaction with the phone (in particular incoming calls). These windows are normally placed above all applications, but behind the status bar. In multiuser systems shows on all users' windows.
就是說設定了這個屬性之後,這個視窗會在所以的介面之上,但是在狀態列的下面。在多使用者系統中,所有使用者的視窗上都會顯示。
定義拖動和點選事件:
mFloatView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
wmParams.x = sWidth - (int) event.getRawX() - mFloatLayout.getMeasuredWidth() / 2;
wmParams.y = sHeight - (int) event.getRawY() - mFloatLayout.getMeasuredHeight() / 2;
if(wmParams.y > sHeight - titleHeight){
return true;
}
//重新整理
mWindowManager.updateViewLayout(mFloatLayout, wmParams);
return false;
}
});
mFloatView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
web.reload();
}
});
別忘了許可權宣告:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />效果圖:

相關文章
- 懸浮窗的一種實現 | Android懸浮窗Window應用Android
- Android 懸浮窗Android
- Android 輔助許可權與懸浮窗Android
- Android懸浮窗的學習Android
- 短視訊app原始碼,連麥時最小化出現可移動懸浮窗APP原始碼
- 下沉式通知的一種實現 | Android懸浮窗Window應用Android
- Android 懸浮窗 System Alert WindowAndroid
- 非侵入式無許可權應用內懸浮窗的實現
- Android 攝像頭預覽懸浮窗,可拖動,可顯示在其他app上方AndroidAPP
- 直播軟體原始碼,設定懸浮窗並可進行任意位置的移動原始碼
- 短視訊系統原始碼,關於懸浮窗的縮放、拖動等應用原始碼
- Android仿微信文章懸浮窗效果Android
- Android 攝像頭預覽懸浮窗Android
- 【轉載】使用WindowManage實現Android懸浮窗Android
- Android中的懸浮框Android
- Flink的滾動視窗、會話視窗、滑動視窗及其應用會話
- 如何獲取Vivo系統的懸浮窗許可權狀態
- Android懸浮框的實現Android
- 如何在macOS中透過應用程式視窗浮動註釋Mac
- Fluid Browser for Mac(多工懸浮透明視窗瀏覽器)1.6啟用版UIMac瀏覽器
- 直播原始碼,懸浮窗滾動漸變色效果原始碼
- Android:會呼吸的懸浮氣泡Android
- Android懸浮窗怎麼簡單實現?這樣用 kotlin編寫輕鬆搞定!AndroidKotlin
- 微信小程式懸浮可拖動客服元件微信小程式元件
- QPM 之懸浮窗設定資訊
- QPM 之懸浮窗助力效能優化優化
- 懸浮窗開發設計實踐
- 小米 TYPE_TOAST 懸浮窗無效的原因AST
- Android懸浮框的適配問題Android
- Android應用視窗突破手機侷限性Android
- 直播平臺製作,Android 懸浮窗延時5秒返回APP問題AndroidAPP
- Android通過WindowManager實現懸浮框Android
- 百度地圖新增懸浮窗搜尋功能地圖
- [轉]Android輕鬆實現RecyclerView懸浮條AndroidView
- 記一次懸浮窗的上線以及坑點總結
- 介紹一款可懸浮的截圖軟體
- Android移動應用知識點總彙①Android
- Finder浮動視窗查詢器:Finder Windows for mac v1.5.14啟用版WindowsMac
- Android RecyclerView實現頭部懸浮吸頂效果AndroidView