苏州网站制作方法,软件下载网站排行榜前十名,腾讯广告联盟,建什么类型个人网站比较好1.前言
在14.0的系统rom产品定制化开发中#xff0c;在进行launcher3的定制化中#xff0c;在双层改为单层的开发中#xff0c;在原生的分页 是横线#xff0c;而为了美观就采用了系统原来的另外一种分页方式#xff0c;就是圆点比较美观#xff0c;接下来就来分析下相关…1.前言
在14.0的系统rom产品定制化开发中在进行launcher3的定制化中在双层改为单层的开发中在原生的分页 是横线而为了美观就采用了系统原来的另外一种分页方式就是圆点比较美观接下来就来分析下相关的实现然后实现其功能
2.Launcher3定制化之桌面分页横线改成圆点显示功能实现的核心类 packages/apps/Launcher3/res/layout/launcher.xmlpackages/apps/Launcher3/src/com/android/launcher3/pageindicators/PageIndicatorDots.java
3.Launcher3定制化之桌面分页横线改成圆点显示功能实现的核心功能分析和实现
在Launcher3中的核心布局中最核心的就是workspace hotseat folder等核心部件中在 Launcher3中的核心布局的相关控件就是在launcher.xml中这个Launcher主页面中显示的这里显示Launcher3桌面的核心控件 DragLayer Workspace WorkspacePageIndicatorLine drop_target_bar hotseat等主要控件的布局 在这里面WorkspacePageIndicatorLine就是所谓的分页横线控件而PageIndicatorDots.java就是 Launcher3的另外一种分页圆点显示控件所以接下来分析下launcher.xml的相关源码
3.1 launcher.xml中相关部件源码分析
在实现Launcher3定制化之桌面分页横线改成圆点显示功能实现的核心功能中通过上述的分析得知 在launcher.xml中的相关源码中这里就是关于桌面布局的核心布局文件接下来看下相关源码修改 com.android.launcher3.LauncherRootViewxmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:launcherhttp://schemas.android.com/apk/res-autoandroid:idid/launcherandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:fitsSystemWindowstruecom.android.launcher3.dragndrop.DragLayerandroid:idid/drag_layerandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:clipChildrenfalseandroid:clipToPaddingfalseandroid:importantForAccessibilitynocom.android.launcher3.views.AccessibilityActionsViewandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:contentDescriptionstring/home_screen/!-- The workspace contains 5 screens of cells --!-- DO NOT CHANGE THE ID --com.android.launcher3.Workspaceandroid:idid/workspaceandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:layout_gravitycenterandroid:themestyle/HomeScreenElementThemelauncher:pageIndicatorid/page_indicator /!-- DO NOT CHANGE THE ID --includeandroid:idid/hotseatlayoutlayout/hotseat /- com.sprd.ext.pageindicators.WorkspacePageIndicatorLine com.android.launcher3.pageindicators.PageIndicatorDotsandroid:idid/page_indicatorandroid:layout_widthmatch_parentandroid:layout_heightdimen/workspace_page_indicator_heightandroid:layout_gravitybottom|center_horizontalandroid:themestyle/HomeScreenElementTheme /includeandroid:idid/drop_target_barlayoutlayout/drop_target_bar /com.android.launcher3.views.ScrimViewandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:idid/scrim_viewandroid:backgroundandroid:color/transparent /includeandroid:idid/apps_viewlayoutlayout/all_appsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parent /includeandroid:idid/overview_panellayoutlayout/overview_panel //com.android.launcher3.dragndrop.DragLayer/com.android.launcher3.LauncherRootView
通过上述的Launcher3中的核心主屏幕部件launcher.xml中的相关源码分析得知在这里 Launcher.xml中的布局文件中com.android.launcher3.pageindicators.WorkspacePageIndicator 就是Launcher3主屏幕的workspaces的布局分页横线控件的显示分页的所以需要改成 圆点分页控件就需要修改为com.android.launcher3.pageindicators.PageIndicatorDots 这样通过上述的修改就完成了修改为Launcher3布局分页圆点显示的功能的修改接下来 看下其他方面关于横线替换成圆点的相关修改接下来分析下PageIndicatorDots.java 中的相关源码实现
3.2 PageIndicatorDots中关于实现圆点绘制布局的相关源码的修改
通过上述的Launcher3中的核心控件的分析 和以前在10.0到12.0的相关修改横线分页到 圆点分页都是需要实现 setInsets(Rect insets)等相关方法的通过这些的修改来 完成对圆点分页的适配工作接下来具体分析下PageIndicatorDots中的相关源码布局 通过在Insettable中的接口实现 setInsets(Rect insets)来在这个类里面添加具体的方法 import com.android.launcher3.R;import com.android.launcher3.Utilities;import com.android.launcher3.util.Themes;-import com.android.launcher3.Launcher;import android.graphics.Rect;import com.android.launcher3.DeviceProfile;import android.view.Gravity;import android.widget.FrameLayout;import com.android.launcher3.Insettable;-public class PageIndicatorDots extends View implements PageIndicator {public class PageIndicatorDots extends View implements Insettable,PageIndicator {private float mCurrentPosition;private float mFinalPosition;private ObjectAnimator mAnimator;- private Launcher mLauncher;private float[] mEntryAnimationRadiusFactors;public PageIndicatorDots(Context context) { -114,7 119,7 public class PageIndicatorDots extends View implements PageIndicator {mCirclePaint.setColor(Themes.getAttrColor(context, R.attr.folderPaginationColor));mDotRadius getResources().getDimension(R.dimen.page_indicator_dot_size) / 2;setOutlineProvider(new MyOutlineProver());- mLauncher Launcher.getLauncher(context);mIsRtl Utilities.isRtl(getResources());}
Launcher3定制化之桌面分页横线改成圆点显示功能实现的核心功能中通过上述的分析得知 在上述的PageIndicatorDots方法中通过实现Insettable的接口接下来就可以在 这里添加setInsets(Rect insets)的实现通过需要实例化Launcher的实现在实现 setInsets(Rect insets)的时候用到相关的实现具体实现如下 Override public void setInsets(Rect insets) { DeviceProfile grid mLauncher.getDeviceProfile(); FrameLayout.LayoutParams lp (FrameLayout.LayoutParams) getLayoutParams(); if (grid.isVerticalBarLayout()) { Rect padding grid.workspacePadding; lp.leftMargin padding.left grid.workspaceCellPaddingXPx; lp.rightMargin padding.right grid.workspaceCellPaddingXPx; lp.bottomMargin padding.bottom; } else { lp.leftMargin lp.rightMargin 0; lp.gravity Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; lp.bottomMargin grid.hotseatBarSizePx insets.bottom; } setLayoutParams(lp); }
在通过在使用的过程中会发现在计算分页数量的时候这里会出现异常所以需要在 异常的地方做修改排除分页滚动为0的情况具体分析实现如下 Overridepublic void setScroll(int currentScroll, int totalScroll) {if (SHOW_DOT_PAGINATION.get() mActivePage ! 0 currentScroll 0) {CURRENT_POSITION.set(this, (float) mActivePage);return;}if (mNumPages 1) {return;}if (mShouldAutoHide) {animatePaginationToAlpha(VISIBLE_ALPHA);}if (mIsRtl) {currentScroll totalScroll - currentScroll;}int scrollPerPage totalScroll / (mNumPages - 1); if(scrollPerPage 0)return;int pageToLeft currentScroll / scrollPerPage;int pageToLeftScroll pageToLeft * scrollPerPage;int pageToRightScroll pageToLeftScroll scrollPerPage; -336,4 342,22 public class PageIndicatorDots extends View implements PageIndicator {}}}
通过上面几部分的修改在Launcher3中就完美实现了在双层改成单层的时候关于分页横线 修改为分页圆点的核心功能的实现最终就完成了功能的实现