StatusBar 高度计算 设置background后需要重新设置padding
This commit is contained in:
@@ -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.client.R;
|
||||
import com.zhidao.adas.client.adapter.ConnectStatusAdapter;
|
||||
import com.zhidao.adas.client.adapter.DataShowAdapter;
|
||||
@@ -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);
|
||||
// 手指移动的时候更新小悬浮窗的位置
|
||||
@@ -157,25 +158,4 @@ public class FloatWindow implements View.OnTouchListener {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.AppCompatButton;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.util.BarUtils;
|
||||
import com.zhidao.adas.client.R;
|
||||
import com.zhidao.adas.client.bean.SpecialVehicleBean;
|
||||
import com.zhidao.adas.client.bean.SpecialVehicleOption;
|
||||
@@ -129,9 +130,9 @@ public class SpecialVehicleFloatWindow extends LinearLayout {
|
||||
mInViewY = event.getY();
|
||||
// 获取相对屏幕的坐标,即以屏幕左上角为原点
|
||||
mDownInScreenX = event.getRawX();
|
||||
mDownInScreenY = event.getRawY() - getSysBarHeight(getContext());
|
||||
mDownInScreenY = event.getRawY() - BarUtils.getStatusBarHeight();
|
||||
mInScreenX = event.getRawX();
|
||||
mInScreenY = event.getRawY() - getSysBarHeight(getContext());
|
||||
mInScreenY = event.getRawY() - BarUtils.getStatusBarHeight();
|
||||
|
||||
if (!isMaximize) {
|
||||
btn_maximize.setPressed(true);
|
||||
@@ -142,7 +143,7 @@ public class SpecialVehicleFloatWindow extends LinearLayout {
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
// 更新浮动窗口位置参数
|
||||
mInScreenX = event.getRawX();
|
||||
mInScreenY = event.getRawY() - getSysBarHeight(getContext());
|
||||
mInScreenY = event.getRawY() - BarUtils.getStatusBarHeight();
|
||||
wmParams.x = (int) (mInScreenX - mInViewX);
|
||||
wmParams.y = (int) (mInScreenY - mInViewY);
|
||||
updateViewLayout();
|
||||
@@ -195,24 +196,7 @@ public class SpecialVehicleFloatWindow extends LinearLayout {
|
||||
// 获取系统状态栏高度
|
||||
private int sbar = -1;
|
||||
|
||||
public int getSysBarHeight(Context contex) {
|
||||
if (sbar == -1) {
|
||||
Class<?> c;
|
||||
Object obj;
|
||||
Field field;
|
||||
int x;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*****************************业务逻辑*******************************************/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user