上文中,我讲到了状态栏的视图是在PhoneStatusBar.java中进行的的。通俗意义上我们所讲的状态栏,是由多个视图部分组成,有ExpandView,PhoneStatusBarView等。我的项目中,此次是需要把状态来移动到底部,经过查找,
protected int getStatusBarGravity() {
return Gravity.TOP | Gravity.FILL_HORIZONTAL;
}
这个函数,返回的是PhoneStatusBarView的Gravity, 所以现在只需把Gravity.TOP 改成BOTTOM 就OK了。但是,当我上拉的时候发现,原来的下拉列表出不来了,于是我将PhoneWindowManager中的所有Gravity.TOP 改成了BOTTOM。然后修改
从代码中可以看出,当我在状态栏范围内按下的时候,它会根据我按下的点的坐标值,屏幕的高度,以及是否现在已经是滑动的状态来判断是否对滑动下拉菜单进行初始化,也就是那个 prepareTracking(y, !mExpanded);// opening if we're not already fully visible 方法, 通过LOG信息判断,上拉没有反应是因为y的值一直负的,于是修改Y值为
final int y = 480 - Math.abs((int)event.getRawY());
这样就可以获得和之前一样的Y坐标值,总算是有反应了,不过还是有点小bug,就是时间显示的那一栏和下拉列表之间有段间隙以及在全屏的时候,底部有时间的那一块去不掉。在
void updateExpandedViewPos(int expandedPosition)中,修改如下
boolean visible = (mTrackingPosition + mTrackingView.getHeight()) > h;
if (!visible) {
// if the contents aren't visible, move the expanded view way off screen
// because the window itself extends below the content view.
mExpandedParams.y = -disph;
}
mExpandedDialog.getWindow().setAttributes(mExpandedParams);
// As long as this isn't just a repositioning that's not supposed to affect
// the user's perception of what's showing, call to say that the visibility
// has changed. (Otherwise, someone else will call to do that).
if (expandedPosition != EXPANDED_LEAVE_ALONE) {
if (SPEW) Slog.d(TAG, "updateExpandedViewPos visibilityChanged(" + visible + ")");
visibilityChanged(visible);
}
改成
boolean interceptTouchEvent(MotionEvent event)
final int action = event.getAction();
final int statusBarSize = mStatusBarView.getHeight();
final int hitSize = statusBarSize*2;
final int y = 480 - Math.abs((int)event.getRawY());
if (action == MotionEvent.ACTION_DOWN) {
if (!mExpanded) {
mViewDelta = statusBarSize - y;
} else {
mTrackingView.getLocationOnScreen(mAbsPos);
mViewDelta = mAbsPos[1] + mTrackingView.getHeight() - y;
}
if ((!mExpanded && y < hitSize) ||
(mExpanded && y > (mDisplayMetrics.heightPixels-hitSize))) {
// We drop events at the edge of the screen to make the windowshade come
// down by accident less, especially when pushing open a device with a keyboard
// that rotates (like g1 and droid)
int x = (int)event.getRawX();
final int edgeBorder = mEdgeBorder;
if (x >= edgeBorder && x < mDisplayMetrics.widthPixels - edgeBorder) {
prepareTracking(y, !mExpanded);// opening if we're not already fully visible
trackMovement(event);
}
}
}
boolean invisible = (mTrackingPosition + mTrackingView.getHeight()) ==0; //> h;
mExpandedParams.y = mTrackingPosition;
if (invisible) {
// if the contents aren't visible, move the expanded view way off screen
// because the window itself extends below the content view.
mExpandedParams.y = -disph;
}
mExpandedDialog.getWindow().setAttributes(mExpandedParams);
// As long as this isn't just a repositioning that's not supposed to affect
// the user's perception of what's showing, call to say that the visibility
// has changed. (Otherwise, someone else will call to do that).
if (expandedPosition != EXPANDED_LEAVE_ALONE) {
if (SPEW) Slog.d(TAG, "updateExpandedViewPos visibilityChanged(" + invisible + ")");
visibilityChanged(invisible);
}
int getExpandedHeight(int disph) {
if (DEBUG) {
Slog.d(TAG, "getExpandedHeight(" + disph + "): sbView="
+ mStatusBarView.getHeight() + " closeView=" + mCloseView.getHeight());
}
return disph - mStatusBarView.getHeight() - mCloseView.getHeight();
}
改成
int getExpandedHeight(int disph) {
if (DEBUG) {
Slog.d(TAG, "getExpandedHeight(" + disph + "): sbView="
+ mStatusBarView.getHeight() + " closeView=" + mCloseView.getHeight());
}
return 480 - mStatusBarView.getHeight();//disph - mStatusBarView.getHeight() - mCloseView.getHeight();
}
问题解决,移动到底部完成,初步测试正常