StatusBar 高度计算 设置background后需要重新设置padding

This commit is contained in:
yangyakun
2022-11-18 12:49:34 +08:00
parent 1607c60435
commit 4be507613b
23 changed files with 108 additions and 302 deletions

View File

@@ -12,6 +12,7 @@ import android.view.WindowManager;
import androidx.recyclerview.widget.RecyclerView;
import com.mogo.eagle.core.utilcode.util.BarUtils;
import com.zhidao.adas.magic.R;
import com.zhidao.adas.magic.adapter.ConnectStatusAdapter;
import com.zhidao.adas.magic.bean.IPCConnectState;
@@ -108,14 +109,14 @@ public class FloatWindow implements View.OnTouchListener {
mInViewY = motionEvent.getY();
// 获取相对屏幕的坐标,即以屏幕左上角为原点
mDownInScreenX = motionEvent.getRawX();
mDownInScreenY = motionEvent.getRawY() - getSysBarHeight(mContext);
mDownInScreenY = motionEvent.getRawY() - BarUtils.getStatusBarHeight();
mInScreenX = motionEvent.getRawX();
mInScreenY = motionEvent.getRawY() - getSysBarHeight(mContext);
mInScreenY = motionEvent.getRawY() - BarUtils.getStatusBarHeight();
break;
case MotionEvent.ACTION_MOVE:
// 更新浮动窗口位置参数
mInScreenX = motionEvent.getRawX();
mInScreenY = motionEvent.getRawY() - getSysBarHeight(mContext);
mInScreenY = motionEvent.getRawY() - BarUtils.getStatusBarHeight();
mWindowParams.x = (int) (mInScreenX - mInViewX);
mWindowParams.y = (int) (mInScreenY - mInViewY);
// 手指移动的时候更新小悬浮窗的位置
@@ -156,27 +157,4 @@ public class FloatWindow implements View.OnTouchListener {
mFloatLayout.setAlpha(1);
}
private int sbar = -1;
// 获取系统状态栏高度
public int getSysBarHeight(Context contex) {
if (sbar == -1) {
Class<?> c;
Object obj;
Field field;
int x;
sbar = 0;
try {
c = Class.forName("com.android.internal.R$dimen");
obj = c.newInstance();
field = c.getField("status_bar_height");
x = Integer.parseInt(field.get(obj).toString());
sbar = contex.getResources().getDimensionPixelSize(x);
} catch (Exception e1) {
e1.printStackTrace();
}
}
return sbar;
}
}