最近项目要做一个悬浮窗的广告栏,闲来无事,就做了一个demo,不足之处,敬请吐槽!
其实功能非常简单,就是在系统上弹出一个跑马灯的textView,循环播放,就跟电视上一样,时不时在屏幕顶端弹一个广告,播放某某消息。这里我用到了WindowManager跟textView的跑马灯效果,废话不多说,直接上代码:
首先是WindowManager管理类:
package com.demo.windowmanagerdemo.util;
import android.content.Context;
import android.graphics.PixelFormat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import com.demo.lijian.windowmanagerdemo.R;
public class WindowUtils {
private static final String LOG_TAG = "WindowUtils";
private static View mView = null;
private static WindowManager mWindowManager = null;
private static Context mContext = nul

本文介绍了如何在Android应用中实现悬浮窗及其跑马灯效果。通过使用WindowManager管理类,重写TextView并设置focusable为true,启用ellipsize的marquee效果,再配合XML布局实现单行显示。同时,别忘了在代码中调用WindowUtils方法来控制显示和隐藏,并确保应用拥有悬浮窗权限,例如在魅族手机上可以在手机管家中开启。
最低0.47元/天 解锁文章
2932

被折叠的 条评论
为什么被折叠?



