導航:首頁 > 操作系統 > android懸浮列表

android懸浮列表

發布時間:2022-06-26 07:16:30

android 怎麼設置 懸浮activity

Android懸浮窗實現

下面實現來自於android學習手冊,裡面有實現的可運行的例子還有源碼。android學習手冊包含9個章節,108個例子,源碼文檔隨便看,例子都是可交互,可運行,源碼採用android studio目錄結構,高亮顯示代碼,文檔都採用文檔結構圖顯示,可以快速定位。360手機助手中下載,圖標上有貝殼
實現基礎
Android懸浮窗實現使用WindowManager ,WindowManager介紹
通過Context.getSystemService(Context.WINDOW_SERVICE)可以獲得 WindowManager對象。
每一個WindowManager對象都和一個特定的 Display綁定。
想要獲取一個不同的display的WindowManager,可以用 createDisplayContext(Display)來獲取那個display的 Context,之後再使用:Context.getSystemService(Context.WINDOW_SERVICE)來獲取WindowManager。
使用WindowManager可以在其他應用最上層,甚至手機桌面最上層顯示窗口。
調用的是WindowManager繼承自基類的addView方法和removeView方法來顯示和隱藏窗口。具體見後面的實例。
另:API 17推出了Presentation,它將自動獲取display的Context和WindowManager,可以方便地在另一個display上顯示窗口。

WindowManager實現懸浮窗需要聲明許可權
首先在manifest中添加如下許可權:
<!-- 顯示頂層浮窗 --><uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

注意:在MIUI上需要在設置中打開本應用的」顯示懸浮窗」開關,並且重啟應用,否則懸浮窗只能顯示在本應用界面內,不能顯示在手機桌面上。

服務獲取和基本參數設置
[java] view plain print?
// 獲取應用的Context
mContext = context.getApplicationContext();
// 獲取WindowManager
mWindowManager = (WindowManager) mContext
.getSystemService(Context.WINDOW_SERVICE);
參數設置:
final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
// 類型
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
// WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
// 設置flag
int flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
// | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
// 如果設置了WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,彈出的View收不到Back鍵的事件
params.flags = flags;
// 不設置這個彈出框的透明遮罩顯示為黑色
params.format = PixelFormat.TRANSLUCENT;
// FLAG_NOT_TOUCH_MODAL不阻塞事件傳遞到後面的窗口
// 設置 FLAG_NOT_FOCUSABLE 懸浮窗口較小時,後面的應用圖標由不可長按變為可長按
// 不設置這個flag的話,home頁的劃屏會有問題
params.width = LayoutParams.MATCH_PARENT;
params.height = LayoutParams.MATCH_PARENT;
params.gravity = Gravity.CENTER;

// 獲取應用的Context
mContext = context.getApplicationContext();
// 獲取WindowManager
mWindowManager = (WindowManager) mContext
.getSystemService(Context.WINDOW_SERVICE);
//參數設置:
final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
// 類型
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
// WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
// 設置flag
int flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
// | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
// 如果設置了WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,彈出的View收不到Back鍵的事件
params.flags = flags;
// 不設置這個彈出框的透明遮罩顯示為黑色
params.format = PixelFormat.TRANSLUCENT;
// FLAG_NOT_TOUCH_MODAL不阻塞事件傳遞到後面的窗口
// 設置 FLAG_NOT_FOCUSABLE 懸浮窗口較小時,後面的應用圖標由不可長按變為可長按
// 不設置這個flag的話,home頁的劃屏會有問題
params.width = LayoutParams.MATCH_PARENT;
params.height = LayoutParams.MATCH_PARENT;
params.gravity = Gravity.CENTER;
點擊和按鍵事件
除了View中的各個控制項的點擊事件之外,彈窗View的消失控制需要一些處理。
點擊彈窗外部可隱藏彈窗的效果,首先,懸浮窗是全屏的,只不過最外層的是透明或者半透明的:

具體實現
[java] view plain print?
package com.robert.floatingwindow;
import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
/**
* 彈窗輔助類
*
* @ClassName WindowUtils
*
*
*/
public class WindowUtils {
private static final String LOG_TAG = "WindowUtils";
private static View mView = null;
private static WindowManager mWindowManager = null;
private static Context mContext = null;
public static Boolean isShown = false;
/**
* 顯示彈出框
*
* @param context
* @param view
*/
public static void showPopupWindow(final Context context) {
if (isShown) {
LogUtil.i(LOG_TAG, "return cause already shown");
return;
}
isShown = true;
LogUtil.i(LOG_TAG, "showPopupWindow");
// 獲取應用的Context
mContext = context.getApplicationContext();
// 獲取WindowManager
mWindowManager = (WindowManager) mContext
.getSystemService(Context.WINDOW_SERVICE);
mView = setUpView(context);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
// 類型
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
// WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
// 設置flag
int flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
// | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
// 如果設置了WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,彈出的View收不到Back鍵的事件
params.flags = flags;
// 不設置這個彈出框的透明遮罩顯示為黑色
params.format = PixelFormat.TRANSLUCENT;
// FLAG_NOT_TOUCH_MODAL不阻塞事件傳遞到後面的窗口
// 設置 FLAG_NOT_FOCUSABLE 懸浮窗口較小時,後面的應用圖標由不可長按變為可長按
// 不設置這個flag的話,home頁的劃屏會有問題
params.width = LayoutParams.MATCH_PARENT;
params.height = LayoutParams.MATCH_PARENT;
params.gravity = Gravity.CENTER;
mWindowManager.addView(mView, params);
LogUtil.i(LOG_TAG, "add view");
}
/**
* 隱藏彈出框
*/
public static void hidePopupWindow() {
LogUtil.i(LOG_TAG, "hide " + isShown + ", " + mView);
if (isShown && null != mView) {
LogUtil.i(LOG_TAG, "hidePopupWindow");
mWindowManager.removeView(mView);
isShown = false;
}
}
private static View setUpView(final Context context) {
LogUtil.i(LOG_TAG, "setUp view");
View view = LayoutInflater.from(context).inflate(R.layout.popupwindow,
null);
Button positiveBtn = (Button) view.findViewById(R.id.positiveBtn);
positiveBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LogUtil.i(LOG_TAG, "ok on click");
// 打開安裝包
// 隱藏彈窗
WindowUtils.hidePopupWindow();
}
});
Button negativeBtn = (Button) view.findViewById(R.id.negativeBtn);
negativeBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LogUtil.i(LOG_TAG, "cancel on click");
WindowUtils.hidePopupWindow();
}
});
// 點擊窗口外部區域可消除
// 這點的實現主要將懸浮窗設置為全屏大小,外層有個透明背景,中間一部分視為內容區域
// 所以點擊內容區域外部視為點擊懸浮窗外部
final View popupWindowView = view.findViewById(R.id.popup_window);// 非透明的內容區域
view.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
LogUtil.i(LOG_TAG, "onTouch");
int x = (int) event.getX();
int y = (int) event.getY();
Rect rect = new Rect();
popupWindowView.getGlobalVisibleRect(rect);
if (!rect.contains(x, y)) {
WindowUtils.hidePopupWindow();
}
LogUtil.i(LOG_TAG, "onTouch : " + x + ", " + y + ", rect: "
+ rect);
return false;
}
});
// 點擊back鍵可消除
view.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
WindowUtils.hidePopupWindow();
return true;
default:
return false;
}
}
});
return view;
}
}

㈡ android以懸浮窗顯示listview,無法顯示

看看官方文檔,對於懸浮框的要求,也許源碼就要求只能是按鈕也說不定的。

㈢ Android 標題懸浮列表

button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog dialog = new AlertDialog.Builder(activity).create(); dialog.setIcon(R.drawable.ico); dialog.setTitle(title); dialog.setMessage(msg); dialog.setButton("OK", new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setCanceledOnTouchOutside(true);//這個是點擊懸浮框外消失 dialog.show(); } });

㈣ Android 選項卡菜單中更多按鈕出現懸浮菜單

親親,樓主,你的這個懸浮菜單怎麼實現的啊,急急急啊,我正不會呢,希望不吝賜教!我是剛注冊的所以沒有懸賞不好意思啊,要是給了答案以後一定把懸賞補上,謝了!

㈤ 如何在Android中實現懸浮Activity

讓Activity使用以下兩個theme中的一個就可以做到。
1)android:theme="@android:style/Theme.Dialog"

2)android:theme="@android:style/Theme.Translucent"

我們還可以使用自定義style實現得更徹底一點
<style name="Translucent" parent="@android:style/Theme.Translucent">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:backgroundDimEnabled">true</item>
</style>

然後在Manifest文件中這樣注冊Activity
<activity android:name=".MainActivity"
android:theme="@style/Translucent"
android:label="@string/app_name">
</activity>

㈥ android java 怎麼設置懸浮窗(懸浮窗是一個activity)上組件的屬性,和按鈕的點擊

@Override
public void onClick(View v) {
final EditText et = new EditText(context) ;
new AlertDialog.Builder(context)
.setTitle("說明")
.setMessage("單個頁卡內按鈕事件測試")
.setView(et)
.setPositiveButton("確定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "單擊確定按鈕", Toast.LENGTH_LONG).show() ;
}
}).setNegativeButton("取消",null).show();
}

㈦ 安卓懸浮球怎麼設置

懸浮球的設置方法:
進入設置--快捷與輔助/更多設置--懸浮球中,將懸浮球開啟。(部分機型不支持懸浮球)

㈧ Android如何只在應用內顯示懸浮窗

Android懸浮窗實現使用WindowManager ,WindowManager介紹

通過Context.getSystemService(Context.WINDOW_SERVICE)可以獲得 WindowManager對象。

每一個WindowManager對象都和一個特定的 Display綁定。
想要獲取一個不同的display的WindowManager,可以用 createDisplayContext(Display)來獲取那個display的 Context,之後再使用:Context.getSystemService(Context.WINDOW_SERVICE)來獲取WindowManager。
使用WindowManager可以在其他應用最上層,甚至手機桌面最上層顯示窗口。
調用的是WindowManager繼承自基類的addView方法和removeView方法來顯示和隱藏窗口。具體見後面的實例。
另:API 17推出了Presentation,它將自動獲取display的Context和WindowManager,可以方便地在另一個display上顯示窗口。


㈨ 在android中怎樣讓按鈕漂浮在圖片上

android懸浮按鈕(Floating action button)的兩種實現方法

最近android中有很多新的設計規范被引入,最流行的莫過於被稱作Promoted Actions的設計了,Promoted Actions是指一種操作按鈕,它不是放在actionbar中,而是直接在可見的UI布局中(當然這里的UI指的是setContentView所管轄的范圍)。因此它更容易在代碼中被獲取到(試想如果你要在actionbar中獲取一個菜單按鈕是不是很難?),Promoted Actions往往主要用於一個界面的主要操作,比如在email的郵件列表界面,promoted action可以用於接受一個新郵件。promoted action在外觀上其實就是一個懸浮按鈕,更常見的是漂浮在界面上的圓形按鈕,一般我直接將promoted action稱作懸浮按鈕,英文名稱Float Action Button簡稱(FAB,不是FBI哈)。

floatactionbutton是android l中的產物,但是我們也可以在更早的版本中實現。假設我這里有一個列表界面,我想使用floatactionbutton代表添加新元素的功能,界面如下:

要實現floatactionbutton可以有多種方法,一種只適合android L,另外一種適合任意版本。

用ImageButton實現

這種方式其實是在ImageButton的屬性中使用了android L才有的一些特性:

<ImageButton

android:layout_width="56dp"

android:layout_height="56dp"

android:src="@drawable/plus"

android:layout_alignParentBottom="true"

android:layout_alignParentRight="true"

android:layout_marginRight="16dp"

android:layout_marginBottom="16dp"

android:tint="@android:color/white"

android:id="@+id/fab"

android:elevation="1dp"

android:background="@drawable/ripple"

android:stateListAnimator="@anim/fab_anim"

/>

仔細一點,你會發現我們將這個ImageButton放到了布局的右下角,為了實現floatactionbutton應該具備的效果,需要考慮以下幾個方面:

·Background

·Shadow

·Animation

背景上我們使用ripple drawable來增強吸引力。注意上面的xml代碼中我們將background設置成了@drawable/ripple,ripple drawable的定義如下:

<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:colorControlHighlight">

<item>

<shape android:shape="oval">

<solid android:color="?android:colorAccent" />

</shape>

</item>

</ripple>

既然是懸浮按鈕,那就需要強調維度上面的感覺,當按鈕被按下的時候,按鈕的陰影需要擴大,並且這個過程是漸變的,我們使用屬性動畫去改變translatioz。

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item

android:state_enabled="true"

android:state_pressed="true">

<objectAnimator

android:ration="@android:integer/config_shortAnimTime"

android:propertyName="translationZ"

android:valueFrom="@dimen/start_z"

android:valueTo="@dimen/end_z"

android:valueType="floatType" />

</item>

<item>

<objectAnimator

android:ration="@android:integer/config_shortAnimTime"

android:propertyName="translationZ"

android:valueFrom="@dimen/end_z"

android:valueTo="@dimen/start_z"

android:valueType="floatType" />

</item>

</selector>

使用自定義控制項的方式實現懸浮按鈕

這種方式不依賴於android L,而是碼代碼。

首先定義一個這樣的類:


public class CustomFAB extends ImageButton {

...

}

然後是讀取一些自定義的屬性(假設你了解styleable的用法)


private void init(AttributeSet attrSet) {

Resources.Theme theme = ctx.getTheme();

TypedArray arr = theme.obtainStyledAttributes(attrSet, R.styleable.FAB, 0, 0);

try {

setBgColor(arr.getColor(R.styleable.FAB_bg_color, Color.BLUE));

setBgColorPressed(arr.getColor(R.styleable.FAB_bg_color_pressed, Color.GRAY));

StateListDrawable sld = new StateListDrawable();

sld.addState(new int[] {android.R.attr.state_pressed}, createButton(bgColorPressed));

sld.addState(new int[] {}, createButton(bgColor));

setBackground(sld);

}

catch(Throwable t) {}

finally {

arr.recycle();

}

}

在xml中我們需要加入如下代碼,一般是在attr.xml文件中。


<?xml version="1.0" encoding="utf-8"?>

<resources>

<declare-styleable name="FAB">

<!-- Background color -->

<attr name="bg_color" format="color|reference"/>

<attr name="bg_color_pressed" format="color|reference"/>

</declare-styleable>

</resources>


使用StateListDrawable來實現不同狀態下的背景


private Drawable createButton(int color) {

OvalShape oShape = new OvalShape();

ShapeDrawable sd = new ShapeDrawable(oShape);

setWillNotDraw(false);

sd.getPaint().setColor(color);

OvalShape oShape1 = new OvalShape();

ShapeDrawable sd1 = new ShapeDrawable(oShape);

sd1.setShaderFactory(new ShapeDrawable.ShaderFactory() {

@Override

public Shader resize(int width, int height) {

LinearGradient lg = new LinearGradient(0,0,0, height,

new int[] {

Color.WHITE,

Color.GRAY,

Color.DKGRAY,

Color.BLACK

}, null, Shader.TileMode.REPEAT);

return lg;

}

});

LayerDrawable ld = new LayerDrawable(new Drawable[] { sd1, sd });

ld.setLayerInset(0, 5, 5, 0, 0);

ld.setLayerInset(1, 0, 0, 5, 5);

return ld;

}

最後將控制項放xml中:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

xmlns:custom="http://schemas.android.com/apk/res/com.survivingwithandroid.fab"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:paddingBottom="@dimen/activity_vertical_margin"

tools:context=".MyActivity">

...

<com.survivingwithandroid.fab.CustomFAB

android:layout_width="56dp"

android:layout_height="56dp"

android:src="@android:drawable/ic_input_add"

android:layout_alignParentBottom="true"

android:layout_alignParentRight="true"

android:layout_marginRight="16dp"

android:layout_marginBottom="16dp"

custom:bg_color="@color/light_blue"

android:tint="@android:color/white"

/>

</RelativeLayout>

㈩ Android桌面懸浮窗效果怎麼實現

可以根據項目需要改變其相應布局。
package com.zk.me;
import java.util.List;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
private WindowManager windowManager = null;
private WindowManager.LayoutParams windowManagerParams = null;
private MyFloatView floatView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);// 取消標題欄
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);// 全屏
setContentView(R.layout.activity_main);
createView();
}
public void onDestroy() {
super.onDestroy();
// 在程序退出(Activity銷毀)時銷毀懸浮窗口
}
private void createView() {
floatView = new MyFloatView(getApplicationContext());
floatView.setOnClickListener(this);
ImageView view = new ImageView(this);
view.setImageResource(R.drawable.ic_launcher);
floatView.addView(view); // 這里簡單的用自帶的icon來做演示
windowManager = (WindowManager) getApplicationContext()
.getSystemService("window");
// 設置LayoutParams(全局變數)相關參數
windowManagerParams = ((FloatApplication) getApplication())
.getWindowParams();
windowManagerParams.type = 2003; // 設置window type
// windowManagerParams.format = PixelFormat.RGBA_8888; // 設置圖片格式,效果為背景透明
// 設置Window flag
windowManagerParams.flags = 40;
windowManagerParams.format = 1;
// 調整懸浮窗口至左上角,便於調整坐標
windowManagerParams.gravity = Gravity.LEFT | Gravity.TOP;
// 以屏幕左上角為原點,設置x、y初始值
windowManagerParams.x = 0;
windowManagerParams.y = 0;
// 設置懸浮窗口長寬數據
windowManagerParams.width = 40;
windowManagerParams.height = 40;
// 顯示myFloatView圖像
windowManager.addView(floatView, windowManagerParams);
}
public void onClick(View v) {
Toast.makeText(this, "Clicked", Toast.LENGTH_SHORT).show();
openCLD("com.jovian.android.pqgl", getApplicationContext());
}
public static void openCLD(String packageName, Context context) {// 打開移動警務應用
PackageManager packageManager = context.getPackageManager();
PackageInfo pi = null;
try {
pi = packageManager.getPackageInfo(packageName, 0);
} catch (NameNotFoundException e) {
}
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
resolveIntent.setPackage(packageName);
List<ResolveInfo> apps = packageManager.queryIntentActivities(
resolveIntent, 0);
ResolveInfo resolveinfo = apps.iterator().next();
if (resolveinfo != null) {
String className = resolveinfo.activityInfo.name;
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName cn = new ComponentName(packageName, className);
intent.setComponent(cn);
context.startActivity(intent);
}
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
package com.zk.me;
import android.content.Context;
import android.graphics.Rect;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.LinearLayout;
public class MyFloatView extends LinearLayout {
private float mTouchX;
private float mTouchY;
private float x;
private float y;
private float mStartX;
private float mStartY;
private OnClickListener mClickListener;
private WindowManager windowManager = (WindowManager) getContext()
.getApplicationContext().getSystemService("window");
// 此windowManagerParams變數為獲取的全局變數,用以保存懸浮窗口的屬性
private WindowManager.LayoutParams windowManagerParams = ((FloatApplication) getContext()
.getApplicationContext()).getWindowParams();
public MyFloatView(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// 獲取到狀態欄的高度
Rect frame = new Rect();
getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
System.out.println("statusBarHeight:" + statusBarHeight);
// 獲取相對屏幕的坐標,即以屏幕左上角為原點
x = event.getRawX();
y = event.getRawY() - statusBarHeight; // statusBarHeight是系統狀態欄的高度
Log.i("tag", "currX" + x + "====currY" + y);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: // 捕獲手指觸摸按下動作
// 獲取相對View的坐標,即以此View左上角為原點
mTouchX = event.getX();
mTouchY = event.getY();
mStartX = x;
mStartY = y;
Log.i("tag", "startX" + mTouchX + "====startY" + mTouchY);
break;
case MotionEvent.ACTION_MOVE: // 捕獲手指觸摸移動動作
updateViewPosition();
break;
case MotionEvent.ACTION_UP: // 捕獲手指觸摸離開動作
updateViewPosition();
mTouchX = mTouchY = 0;
if ((x - mStartX) < 5 && (y - mStartY) < 5) {
if (mClickListener != null) {
mClickListener.onClick(this);
}
}
break;
}
return true;
}
@Override
public void setOnClickListener(OnClickListener l) {
this.mClickListener = l;
}
private void updateViewPosition() {
// 更新浮動窗口位置參數
windowManagerParams.x = (int) (x - mTouchX);
windowManagerParams.y = (int) (y - mTouchY);
windowManager.updateViewLayout(this, windowManagerParams); // 刷新顯示
}
}

閱讀全文

與android懸浮列表相關的資料

熱點內容
安裝包加密有什麼用 瀏覽:584
舍利子靈力演算法 瀏覽:501
javacalendar天數 瀏覽:567
anyview閱讀器java 瀏覽:361
怎麼降為安卓10 瀏覽:996
javaweb程序設計郭 瀏覽:249
gm聲望命令 瀏覽:486
pdf轉換器電腦版免費 瀏覽:43
解壓歌曲什麼歌最好 瀏覽:153
諾貝爾pdf 瀏覽:969
雲伺服器快速安裝系統原理 瀏覽:790
蘋果騰訊管家如何恢復加密相冊 瀏覽:117
手機軟體反編譯教程 瀏覽:860
sqlserver編程語言 瀏覽:650
gpa國際標准演算法 瀏覽:238
伺服器編程語言排行 瀏覽:947
怎麼下載快跑app 瀏覽:967
小紅書app如何保存視頻 瀏覽:172
如何解開系統加密文件 瀏覽:811
linux切換root命令 瀏覽:283