日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

Android Q : 安卓源码、水滴屏适配状态栏图标(图标过多时显示一个点)

發(fā)布時(shí)間:2024/1/18 Android 72 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android Q : 安卓源码、水滴屏适配状态栏图标(图标过多时显示一个点) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

源碼路徑:com.android.systemui.statusbar.phone/StatusIconContainer.java
布局文件路徑:SystemUI/res/layout/status_bar.xml
下拉后狀態(tài)欄布局文件路徑:SystemUI/res/layout/quick_qs_status_icons.xml
鎖屏狀態(tài)欄文件布局:SystemUI/res/layout/keyguard_status_bar.xml

一、狀態(tài)欄布局

在沒(méi)下拉狀態(tài)欄時(shí),原生android會(huì)將狀態(tài)欄分為兩部分(如下圖及布局源碼)
1、android:id=“@+id/notification_icon_area
2、android:id=”@+id/system_icon_area"

從下面的布局文件可以看到這兩塊區(qū)域的權(quán)重都是1,左邊放通知圖標(biāo),右邊放系統(tǒng)圖標(biāo),中間留有一塊控件用來(lái)放缺口(也就是水滴或劉海的位置),在這里如果沒(méi)有水滴的話可以修改權(quán)重,來(lái)放置更多的系統(tǒng)圖標(biāo)或通知圖標(biāo)(有水滴的話改了圖標(biāo)過(guò)多時(shí)就會(huì)遮擋住圖標(biāo))

<FrameLayoutandroid:layout_height="match_parent"android:layout_width="0dp"android:layout_weight="1"><include layout="@layout/heads_up_status_bar_layout" /><!-- The alpha of the left side is controlled by PhoneStatusBarTransitions, and theindividual views are controlled by StatusBarManager disable flags DISABLE_CLOCK andDISABLE_NOTIFICATION_ICONS, respectively --><LinearLayoutandroid:id="@+id/status_bar_left_side"android:layout_height="match_parent"android:layout_width="match_parent"android:clipChildren="false"><ViewStubandroid:id="@+id/operator_name"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout="@layout/operator_name" /><com.android.systemui.statusbar.phone.StatusIconContainer android:id="@+id/statusIcons_left"android:layout_width="wrap_content"android:layout_height="match_parent"android:paddingEnd="@dimen/signal_cluster_battery_padding"android:gravity="center_vertical"android:orientation="horizontal"/><com.android.systemui.statusbar.AlphaOptimizedFrameLayoutandroid:id="@+id/notification_icon_area"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:orientation="horizontal"android:clipChildren="false"/></LinearLayout></FrameLayout><!-- Space should cover the notch (if it exists) and let other views lay out around it --><android.widget.Spaceandroid:id="@+id/cutout_space_view"android:layout_width="0dp"android:layout_height="match_parent"android:gravity="center_horizontal|center_vertical"/><com.android.systemui.statusbar.AlphaOptimizedFrameLayoutandroid:id="@+id/centered_icon_area"android:layout_width="wrap_content"android:layout_height="match_parent"android:orientation="horizontal"android:clipChildren="false"android:gravity="center_horizontal|center_vertical"/><com.android.keyguard.AlphaOptimizedLinearLayout android:id="@+id/system_icon_area"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:orientation="horizontal"android:gravity="center_vertical|end"><LinearLayoutandroid:id="@+id/system_icons"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center_vertical"><com.android.systemui.statusbar.phone.StatusIconContainer android:id="@+id/statusIcons"android:layout_width="0dp"android:layout_weight="1"android:layout_height="match_parent"android:paddingEnd="@dimen/signal_cluster_battery_padding"android:gravity="center_vertical"android:orientation="horizontal"/><com.android.systemui.BatteryMeterView android:id="@+id/battery"android:layout_height="match_parent"android:layout_width="wrap_content"android:clipToPadding="false"android:clipChildren="false"android:textAppearance="@style/TextAppearance.StatusBar.Clock" /><android.widget.Spaceandroid:layout_width="2dp"android:layout_height="match_parent"/><com.android.systemui.statusbar.policy.Clockandroid:id="@+id/clock"android:layout_width="wrap_content"android:layout_height="match_parent"android:textAppearance="@style/TextAppearance.StatusBar.Clock"android:paddingBottom="2dip"android:singleLine="true"android:gravity="center_vertical|end"/></LinearLayout></com.android.keyguard.AlphaOptimizedLinearLayout>

二、狀態(tài)欄右側(cè)系統(tǒng)圖標(biāo)顯示過(guò)多時(shí)顯示一個(gè)點(diǎn)

在源碼中,控制右側(cè)系統(tǒng)圖標(biāo)顯示的有兩個(gè)限制:
1、圖標(biāo)個(gè)數(shù)
2、寬度限制

主要方法:onMeasure 和 calculateIconTranslations (下方貼上源代碼)
在onMeasure中會(huì)測(cè)量水滴右邊區(qū)域能放的下的圖標(biāo)的總寬度(totalWidth)
在calculateIconTranslations中會(huì)判斷如果圖標(biāo)個(gè)數(shù)大于限定個(gè)數(shù)并且剩余寬度不足以繪制一個(gè)圖標(biāo)時(shí),就去繪制那個(gè)點(diǎn),達(dá)到開(kāi)始那張圖的效果

// Max 8 status icons including batteryprivate static final int MAX_ICONS = 7;

安卓原生定義了最大顯示圖標(biāo)個(gè)數(shù)是8個(gè)(包括電池圖標(biāo))

mUnderflowWidth :顯示的點(diǎn)標(biāo)框的寬度
mShouldRestrictIcons:是否需要限制圖標(biāo)的一個(gè)標(biāo)志位,原生代碼中的下拉后的狀態(tài)欄是不限制圖標(biāo)的,就是在QuickStatusBarHeaderController.java中控制這個(gè)變量為false后就不會(huì)去畫(huà)點(diǎn)

@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {mMeasureViews.clear();int mode = MeasureSpec.getMode(widthMeasureSpec);final int width = MeasureSpec.getSize(widthMeasureSpec);//當(dāng)前View的寬度final int count = getChildCount();// Collect all of the views which want to be laid outfor (int i = 0; i < count; i++) {StatusIconDisplayable icon = (StatusIconDisplayable) getChildAt(i);if (icon.isIconVisible() && !icon.isIconBlocked()&& !mIgnoredSlots.contains(icon.getSlot())) {mMeasureViews.add((View) icon);}}int visibleCount = mMeasureViews.size();int maxVisible = visibleCount <= MAX_ICONS ? MAX_ICONS : MAX_ICONS - 1;int totalWidth = mPaddingLeft + mPaddingRight;boolean trackWidth = true;// Measure all children so that they report the correct widthint childWidthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.UNSPECIFIED);mNeedsUnderflow = mShouldRestrictIcons && visibleCount > MAX_ICONS;for (int i = 0; i < mMeasureViews.size(); i++) {// Walking backwardsView child = mMeasureViews.get(visibleCount - i - 1);measureChild(child, childWidthSpec, heightMeasureSpec);// mShouldRestrictIcons:是否限制圖標(biāo)的一個(gè)判斷,原生代碼中的下拉后的狀態(tài)欄是//不限制圖標(biāo)的,就是在QuickStatusBarHeaderController.java中控制這個(gè)變量if (mShouldRestrictIcons) { if (i < maxVisible && trackWidth) {//把不超過(guò)最大個(gè)數(shù)的所有圖標(biāo)的寬度加起來(lái)totalWidth += getViewTotalMeasuredWidth(child);} else if (trackWidth) {// We've hit the icon limit; add space for dots//mUnderflowWidth:最后加上圓點(diǎn)的寬度totalWidth += mUnderflowWidth;trackWidth = false;}} else {totalWidth += getViewTotalMeasuredWidth(child);}}if (mode == MeasureSpec.EXACTLY) {//如果圖標(biāo)個(gè)數(shù)沒(méi)有超過(guò)最大限制的數(shù)量但是圖標(biāo)的總寬度大于View的寬度//此時(shí)也是需要顯示點(diǎn)的,將mNeedsUnderflow 設(shè)置為trueif (!mNeedsUnderflow && totalWidth > width) {mNeedsUnderflow = true;}setMeasuredDimension(width, MeasureSpec.getSize(heightMeasureSpec));} else {if (mode == MeasureSpec.AT_MOST && totalWidth > width) {mNeedsUnderflow = true;totalWidth = width;}setMeasuredDimension(totalWidth, MeasureSpec.getSize(heightMeasureSpec));}} private void calculateIconTranslations() {mLayoutStates.clear();float width = getWidth();//總寬度減去PaddingEnd,獲取不顯示圖標(biāo)時(shí)最大的X偏移量float translationX = width - getPaddingEnd();float contentStart = getPaddingStart();//獲取當(dāng)前需要顯示的圖標(biāo)個(gè)數(shù)int childCount = getChildCount();// Underflow === don't show content until that indexif (DEBUG) android.util.Log.d(TAG, "calculateIconTranslations: start=" + translationX+ " width=" + width + " underflow=" + mNeedsUnderflow);// Collect all of the states which want to be visiblefor (int i = childCount - 1; i >= 0; i--) {View child = getChildAt(i);StatusIconDisplayable iconView = (StatusIconDisplayable) child;StatusIconState childState = getViewStateFromChild(child);if (!iconView.isIconVisible() || iconView.isIconBlocked()|| mIgnoredSlots.contains(iconView.getSlot())) {//滿足以上條件設(shè)置圖標(biāo)狀態(tài)為隱藏childState.visibleState = STATE_HIDDEN;if (DEBUG) Log.d(TAG, "skipping child (" + iconView.getSlot() + ") not visible");continue;}//設(shè)置圖標(biāo)狀態(tài)為顯示childState.visibleState = STATE_ICON;//總X偏移量減去圖標(biāo)的寬度,己算當(dāng)前圖標(biāo)的X軸偏移量,//如果此時(shí)計(jì)算結(jié)果為負(fù)數(shù),則說(shuō)明View中剩余的寬度不足以將此圖標(biāo)顯示完全childState.xTranslation = translationX - getViewTotalWidth(child);mLayoutStates.add(0, childState);translationX -= getViewTotalWidth(child);}// Show either 1-MAX_ICONS icons, or (MAX_ICONS - 1) icons + overflowint totalVisible = mLayoutStates.size();int maxVisible = totalVisible <= MAX_ICONS ? MAX_ICONS : MAX_ICONS - 1;mUnderflowStart = 0;int visible = 0;int firstUnderflowIndex = -1;for (int i = totalVisible - 1; i >= 0; i--) {StatusIconState state = mLayoutStates.get(i);// Allow room for underflow if we found we need it in onMeasure//如果需要畫(huà)點(diǎn),并且當(dāng)前圖標(biāo)的X偏移量小于點(diǎn)標(biāo)框的寬度+padding時(shí),記錄當(dāng)前圖標(biāo)的下標(biāo)if (mNeedsUnderflow && (state.xTranslation < (contentStart + mUnderflowWidth))||(mShouldRestrictIcons && visible >= maxVisible)) {firstUnderflowIndex = i;break;}mUnderflowStart = (int) Math.max(contentStart, state.xTranslation - mUnderflowWidth);visible++;}if (firstUnderflowIndex != -1) {int totalDots = 0;int dotWidth = mStaticDotDiameter + mDotPadding;int dotOffset = mUnderflowStart + mUnderflowWidth - mIconDotFrameWidth;for (int i = firstUnderflowIndex; i >= 0; i--) {//拿到當(dāng)前下標(biāo)的圖標(biāo)狀態(tài)StatusIconState state = mLayoutStates.get(i);//系統(tǒng)定義的MAX_DOTS=1,也就是說(shuō)點(diǎn)圖標(biāo)只會(huì)顯示一個(gè)if (totalDots < MAX_DOTS) {state.xTranslation = dotOffset;//設(shè)置當(dāng)前圖標(biāo)狀態(tài)為點(diǎn)圖標(biāo)state.visibleState = STATE_DOT;dotOffset -= dotWidth;totalDots++;} else {//剩余的圖標(biāo)狀態(tài)都設(shè)置為隱藏state.visibleState = STATE_HIDDEN;}}}// Stole this from NotificationIconContainer. Not optimal but keeps the layout logic cleanif(isLayoutRtl()) {for (int i = 0; i < childCount; i++) {View child = getChildAt(i);StatusIconState state = getViewStateFromChild(child);state.xTranslation = width - state.xTranslation - child.getWidth();}}}

總結(jié)

以上是生活随笔為你收集整理的Android Q : 安卓源码、水滴屏适配状态栏图标(图标过多时显示一个点)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 97人人爽人人 | 性一交一乱一透一a级 | 色婷婷久久一区二区三区麻豆 | 日韩有码视频在线 | 色视屏 | 一区二区高清在线 | 国产午夜精品一区 | 欧美日批 | 成人啪啪 | www.99色| 日日骚一区| 蜜桃精品久久久久久久免费影院 | 欧美不卡一二三 | 国产成人小视频在线观看 | 91免费网站在线观看 | 免费成人美女在线观看 | 欧美日韩在线观看一区二区 | 国产aaa大片 | 亚洲av无码一区二区二三区 | 在线看片亚洲 | 在线视频欧美一区 | 经典三级久久 | 欧美另类视频在线观看 | 日韩成人高清 | 亚洲中文字幕无码不卡电影 | 少妇网站在线观看 | 激情成人综合 | 亚洲高清二区 | 欧美精品一区二区三区久久久竹菊 | 国产日韩欧美二区 | 中文字幕――色哟哟 | 天天操网站 | 精品黑人一区二区三区观看时间 | 99在线无码精品入口 | 日本色片网站 | 大吊一区二区三区 | 日本女人毛片 | 人人澡澡人人 | 四色成人av永久网址 | 麻豆com | 久久精品无码一区二区三区免费 | 亚洲综合视频一区 | 国产偷自拍 | 国产激情av在线 | 91麻豆产精品久久久久久夏晴子 | 国产精品第6页 | 亚洲男女一区二区三区 | 成年人的免费视频 | 揉我啊嗯~喷水了h视频 | 日本xxxx免费 | 中国美女洗澡免费看网站 | 天天操天天插天天射 | 日韩毛片一区 | 亚洲精品视频在线观看免费视频 | 桃色综合网 | 亚洲国产精品国自产拍久久 | 欧美亚洲一区二区在线观看 | 高清一区在线观看 | 免费的av | 国产青青草视频 | 玖玖玖视频 | 成人国产网站 | 国产欧美日韩亚洲 | 成人一区二区在线观看 | 日本国产在线 | 打屁股无遮挡网站 | 三上悠亚中文字幕在线播放 | 色婷婷狠狠爱 | 激情超碰| 欧洲美女与动交ccoo | 亚洲综合视频在线播放 | 床戏高潮做进去大尺度视频 | 四虎永久地址 | 毛片在线视频观看 | 久久久久久国产精品一区 | 99热国产在线 | 一个人在线观看www软件 | 亚洲天堂免费在线观看视频 | 日本高清免费视频 | 久草精品视频在线观看 | 温柔女教师在线观看 | 色a在线 | 黄色三级生活片 | 波多野结衣爱爱 | 不卡av一区二区 | 中国成熟妇女毛茸茸 | 天天爽天天干 | 欧美特级黄色录像 | 日韩大尺度视频 | 午夜毛片 | 亚洲精品av在线 | 五月婷婷激情小说 | 黄色网久久 | 我们2018在线观看免费版高清 | 亚洲成a人| 国产午夜手机精彩视频 | 国产亚洲欧美在线精品 | 国精产品一区一区三区mba下载 | 中文字幕在线视频不卡 |