andorid7.0添加了分屏功能,但是分屏后点击任意按钮暂时退出分屏在二边会出现白边的问题,其实这是原生系统保留的,让用户知道当前正处于分屏模式,分析代码发现留出的白边在framework中dimens.xml中有相应的定义,具体如下:
//分割线的宽度大小
<!-- Width of the window of the divider bar used to resize docked stacks. -->
<dimen name="docked_stack_divider_thickness">48dp</dimen>
<dimen name="docked_stack_divider_thickness">48dp</dimen>
<!-- How much the content in the divider is inset from the window bounds when resting. Used to
calculate the bounds of the stacks-->
<dimen name="docked_stack_divider_insets">19dp</dimen>
calculate the bounds of the stacks-->
<dimen name="docked_stack_divider_insets">19dp</dimen>
//用于定义分屏后最小显示的区域
<!-- To how much the docked stack gets reduced when we decide to minimize the docked stack, i.e.
when the user opens homescreen. -->
<dimen name="docked_stack_minimize_thickness">8dp</dimen>
when the user opens homescreen. -->
<dimen name="docked_stack_minimize_thickness">8dp</dimen>
如要去除白边则需要执行2步
1.修改docked_stack_minimize_thickness的值为0
2.在framework下的taskStack.java中修改adjustForMinimizedDockedStack()此方法,具体修改如下:
modified: ../core/res/res/values/dimens.xml
modified: core/java/com/android/server/wm/TaskStack.java
1.
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -62,7 +62,7 @@
<!-- To how much the docked stack gets reduced when we decide to minimize the docked stack, i.e.
when the user opens homescreen. -->
- <dimen name="docked_stack_minimize_thickness">8dp</dimen>
+ <dimen name="docked_stack_minimize_thickness">0dp</dimen>
<!-- Min width for a tablet device -->
<dimen name="min_xlarge_screen_width">800dp</dimen>
2.
--- a/services/core/java/com/android/server/wm/TaskStack.java
+++ b/services/core/java/com/android/server/wm/TaskStack.java
@@ -95,6 +95,7 @@ public class TaskStack implements DimLayer.DimLayerUser,
/** Whether mBounds is fullscreen */
private boolean mFullscreen = true;
+
// Device rotation as of the last time {@link #mBounds} was set.
int mRotation;
@@ -124,6 +125,7 @@ public class TaskStack implements DimLayer.DimLayerUser,
private float mAdjustImeAmount;
private float mAdjustDividerAmount;
private final int mDockedStackMinimizeThickness;
+ private final int mDividerInsets;
// If this is true, we are in the bounds animating mode.
// The task will be down or upscaled to perfectly fit the
@@ -142,6 +144,8 @@ public class TaskStack implements DimLayer.DimLayerUser,
mDockedStackMinimizeThickness = service.mContext.getResources().getDimensionPixelSize(
com.android.internal.R.dimen.docked_stack_minimize_thickness);
EventLog.writeEvent(EventLogTags.WM_STACK_CREATED, stackId);
+ mDividerInsets = service.mContext.getResources().getDimensionPixelSize(
+ com.android.internal.R.dimen.docked_stack_divider_insets);
}
DisplayContent getDisplayContent() {
@@ -243,6 +247,7 @@ public class TaskStack implements DimLayer.DimLayerUser,
insetBounds = mFullyAdjustedImeBounds;
}
}
alignTasksToAdjustedBounds(adjusted ? mAdjustedBounds : mBounds, insetBounds);
mDisplayContent.layoutNeeded = true;
}
@@ -1044,6 +1049,11 @@ public class TaskStack implements DimLayer.DimLayerUser,
mTmpAdjustedBounds.set(mBounds);
mTmpAdjustedBounds.bottom =
(int) (minimizeAmount * topInset + (1 - minimizeAmount) * mBounds.bottom);
+ if (minimizeAmount == 1) {
+ mTmpAdjustedBounds.top = mTmpAdjustedBounds.top - mTmpAdjustedBounds.bottom;
+ mTmpAdjustedBounds.bottom = -mDividerInsets;
+ }
+ if(mTmpAdjustedBounds.top > mTmpAdjustedBounds.bottom ){
+ mTmpAdjustedBounds.top = mTmpAdjustedBounds.bottom - 1;
+ }
} else if (dockSide == DOCKED_LEFT) {
mTmpAdjustedBounds.set(mBounds);
final int width = mBounds.width();
@@ -1051,11 +1061,27 @@ public class TaskStack implements DimLayer.DimLayerUser,
(int) (minimizeAmount * mDockedStackMinimizeThickness
+ (1 - minimizeAmount) * mBounds.right);
mTmpAdjustedBounds.left = mTmpAdjustedBounds.right - width;
+ if(minimizeAmount==1f){
+ mTmpAdjustedBounds.right =
+ (int) (minimizeAmount * mDockedStackMinimizeThickness
+ + (1 - minimizeAmount) * mBounds.right) - mDividerInsets*3;
+ mTmpAdjustedBounds.left = mTmpAdjustedBounds.right - width - mDividerInsets;
+ }
} else if (dockSide == DOCKED_RIGHT) {
mTmpAdjustedBounds.set(mBounds);
mTmpAdjustedBounds.left =
(int) (minimizeAmount * (mBounds.right - mDockedStackMinimizeThickness)
+ (1 - minimizeAmount) * mBounds.left);
+
+ if(minimizeAmount==1f){
+ mTmpAdjustedBounds.left =
+ (int) (minimizeAmount * (mBounds.right - mDockedStackMinimizeThickness)
+ + (1 - minimizeAmount) * mBounds.left) + mDividerInsets*3;
+ }
+
+ if(mTmpAdjustedBounds.left >= mTmpAdjustedBounds.right){
+ mTmpAdjustedBounds.right = mTmpAdjustedBounds.left + 1;
+ }
}
return true;
}
3.关于分屏时分割条大小的计算主要是基于dockstack的大小来计算的,具体如下DockedStackDividerController.java中的positionDockedStackedDivider方法中,具体方法实现如下:
void positionDockedStackedDivider(Rect frame) {
TaskStack stack = mDisplayContent.getDockedStackLocked();
if (stack == null) {
// Unfortunately we might end up with still having a divider, even though the underlying
// stack was already removed. This is because we are on AM thread and the removal of the
// divider was deferred to WM thread and hasn't happened yet. In that case let's just
// keep putting it in the same place it was before the stack was removed to have
// continuity and prevent it from jumping to the center. It will get hidden soon.
frame.set(mLastRect);
return;
} else {
stack.getDimBounds(mTmpRect);
}
int side = stack.getDockSide();
switch (side) {
case DOCKED_LEFT:
frame.set(mTmpRect.right - mDividerInsets, frame.top,
mTmpRect.right + frame.width() - mDividerInsets, frame.bottom);
break;
case DOCKED_TOP:
frame.set(frame.left, mTmpRect.bottom - mDividerInsets,
mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets);
break;
case DOCKED_RIGHT:
frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top,
mTmpRect.left + mDividerInsets, frame.bottom);
break;
case DOCKED_BOTTOM:
frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets,
frame.right, mTmpRect.top + mDividerInsets);
break;
}
mLastRect.set(frame);
}