Skip to content

Commit

Permalink
修复横板情况下的特殊情况引起的ui问题
Browse files Browse the repository at this point in the history
  • Loading branch information
aaatttcccc committed Jan 17, 2022
1 parent d77529b commit 67ae655
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ import android.view.WindowManager
*/
object DisplayMetricsUtils {

/**
* 获取屏幕分辨率 - 宽高
*
* @param context 上下文
* @return 宽 高,索引0为宽,索引1为高
*/
@JvmStatic
fun getScreenWidthAndHeight(context: Context): IntArray {
val intArray = IntArray(2)
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics = windowManager.currentWindowMetrics
val insets = windowMetrics.windowInsets.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
intArray[0] = windowMetrics.bounds.width() - insets.left - insets.right
intArray[1] = windowMetrics.bounds.height() - insets.bottom - insets.top
} else {
val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
intArray[0] = displayMetrics.widthPixels
intArray[1] = displayMetrics.heightPixels
}
return intArray
}

/**
* 获取屏幕分辨率-宽
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@

import com.zhongjh.albumcamerarecorder.R;
import com.zhongjh.albumcamerarecorder.camera.listener.ClickOrLongListener;
import com.zhongjh.albumcamerarecorder.camera.util.DisplayMetricsSpUtils;
import com.zhongjh.albumcamerarecorder.widget.clickorlongbutton.ClickOrLongButton;
import com.zhongjh.circularprogressview.CircularProgress;
import com.zhongjh.circularprogressview.CircularProgressListener;
import com.zhongjh.common.utils.DisplayMetricsUtils;

import java.util.ArrayList;

import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;

/**
* 集成各个控件的布局
* {@link com.zhongjh.albumcamerarecorder.widget.clickorlongbutton.ClickOrLongButton 点击或者长按的按钮 }
Expand Down Expand Up @@ -133,8 +131,9 @@ public BaseOperationLayout(@NonNull Context context, @Nullable AttributeSet attr

public BaseOperationLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mScreenWidth = DisplayMetricsSpUtils.getScreenWidth(context);
mScreenHeight = DisplayMetricsSpUtils.getScreenHeight(context);
int[] widthAndHeight = DisplayMetricsUtils.getScreenWidthAndHeight(context);
mScreenWidth = widthAndHeight[0];
mScreenHeight = widthAndHeight[1];
initView();
}

Expand Down

0 comments on commit 67ae655

Please sign in to comment.