这边思路就是,写死底部居中,然后把它里面算法的方法直接注释掉,完全依赖xml来布局。
verride/vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/status_bar_expanded.xml
这里面有个
<com.android.keyguard.LockIconView
里面就有
<ImageView
android:id="@+id/lock_icon"
我们只需要在父控件<com.android.keyguard.LockIconView中加个布局
android:layout_gravity="center|bottom"
底部居中。
override/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/keyguard/LockIconViewController.java
这个文件里面有算图标的中心位置在哪的,刚开始的时候会调用onViewAttached,这里面我们把updateConfiguration();这个方法注释掉,因为这个方法如下
private void updateConfiguration() {
final DisplayMetrics metrics = mView.getContext().getResources().getDisplayMetrics();
mWidthPixels = metrics.widthPixels;
mHeightPixels = metrics.heightPixels;
mBottomPadding = mView.getContext().getResources().getDimensionPixelSize(
R.dimen.lock_icon_margin_bottom);
mUnlockedLabel = mView.getContext().getResources().getString(
R.string.accessibility_unlock_button);
mLockedLabel = mView.getContext()
.getResources().getString(R.string.accessibility_lock_icon);
updateLockIconLocation();
}
所以又会到updateLockIconLocation这个方法。
private void updateLockIconLocation() {
if (mUdfpsSupported) {
FingerprintSensorPropertiesInternal props = mAuthController.getUdfpsProps().get(0);
mView.setCenterLocation(new PointF(props.sensorLocationX, props.sensorLocationY),
props.sensorRadius);
} else {
mView.setCenterLocation(
new PointF(mWidthPixels / 2,
mHeightPixels - mBottomPadding /**- sDistAboveKgBottomAreaPx
- sLockIconRadiusPx*/), sLockIconRadiusPx);
}
mView.getHitRect(mSensorTouchLocation);
}
这个方法里面实测只走了else,刚开始初始化onViewAttached,里面有一次计算位置,然后就是每次转屏都会用这个方法再算一次。监听的方法是
private final ConfigurationController.ConfigurationListener mConfigurationListener =
new ConfigurationController.ConfigurationListener() {
里面主要是
public void onConfigChanged(Configuration newConfig) {
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
/*/tyd.yantao 20220808 force xml to display lockIcon
updateConfiguration();
//*/
updateColors();
}
会发现这边源码是一旦转到竖屏又会调用算法再重新设置位置,由于这项目的分辨率改过,所以UI会有问题,原来的算法不行。所以这边也把那个方法注释掉。
解锁图标上面的小字
然后还发现一个问题,就是这个锁在底部会与提示文字重叠,就是提示滑动解锁的文字,所以这边的思路是把底部的文字调高一点。
vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/dimens.xml
改keyguard_indication_margin_bottom
我改成了48dp。
这个主要是KeyguardBottomAreaView
在/status_bar_expanded.xml中就是这个组件,里面应该还有底部的比如说照片快捷 ,只不过这个项目隐藏了吧。
<include
layout="@layout/keyguard_bottom_area"
android:visibility="gone" />