展会信息港展会大全

ICSLauncher改造-替换滑屏Indicator
来源:互联网   发布日期:2016-01-06 19:27:02   浏览:1349次  

导读:[html]背景:鼀生ICS 已经有一种通过9patch拉伸实现的scrollIndicator但是不够美观,本文就在不修改原生scrollindicator的基础上添加新的冒泡scr...

[html]

背景:

原生ICS 已经有一种通过9patch拉伸实现的scrollIndicator但是不够美观,本文就在不修改原生scrollindicator的基础上添加新的冒泡scrollindicator。

效果图如下。实现思路很简单,见正文。

1.添加View对象

1.1 AppScreenBubbleViewFrameLayout extends FrameLayout

每一个“点”是一个AppScreenBubbleViewFrameLayout,它有两个成员变量,imageViewFront、imageViewBack,当前页显示imageViewFront,其他页显示imageViewBack。

1.2 AppScreenBubbleViewFrameLayout extends FrameLayout

[java]

for (int page = 0; page < totalPages; ++page) {

LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,

LayoutParams.WRAP_CONTENT);

AppScreenBubbleViewFrameLayout appScreenBubbleViewFrameLayout = new AppScreenBubbleViewFrameLayout(

mContext);

if (page == mCurrentPage) {

appScreenBubbleViewFrameLayout.getImageViewFront()

.setImageDrawable(getFocusDrawable());

}

else {

appScreenBubbleViewFrameLayout.getImageViewFront()

.setImageDrawable(getNormalDrawable());

}

this.addView(appScreenBubbleViewFrameLayout, layoutParams);

}

1.2添加AppScreenBubbleViewFrameLayout布局文件

[html]

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"

android:layout_width="fill_parent" android:layout_height="wrap_content"

android:scaleType="center" android:layout_gravity="bottom|center_horizontal"

launcher:direction="horizontal">

<com.android.launcher2.AppScreenBubbleView

android:id="@+id/drawer_appscreen_num" android:layout_width="match_parent"

android:layout_height="wrap_content" android:gravity="center_horizontal"/>

</LinearLayout>

2.合入Launcher

2.1在Laucher.xml中添加如下布局

www.2cto.com

<!-- add bubble view -->

<include layout="@layout/workspace_bubble_view_layout"

android:id="@+id/bubbleView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="bottom"

android:layout_marginBottom="@dimen/button_bar_height"/>

2.2.在Laucher.java中初始化

[java]

//add bubbleView to Workspace

View bubbleView = mDragLayer.findViewById(R.id.bubbleView);

mScreenBubbleView = (AppScreenBubbleView) bubbleView.findViewById(R.id.drawer_appscreen_num);

mWorkspace.setAppScreenBubbleView(mScreenBubbleView);

//mScreenBubbleView.show

mWorkspace.showScreenBubbleView(false);

3.PagedView

注意学习动画得使用啊,亲!

[java]

protected void showScreenBubbleView(boolean immediately){

if (getChildCount() <= 1) return;

if(!isScreenBubbleEnable()) return;

getScreenBubbleView();

if(mScreenBubbleView != null){

updateScreenPosition();

mScreenBubbleView.setVisibility(View.VISIBLE);

if (immediately) {

mScreenBubbleView.setAlpha(1f);

}

else{

mScreenBubbleViewAnimator = ObjectAnimator.ofFloat(mScreenBubbleView, "alpha", 1f);

mScreenBubbleViewAnimator.setDuration(sScreenBubbleFadeInDuration);

mScreenBubbleViewAnimator.start();

}

}

}

[java]

// a method that subclasses can override to add behavior

protected void onPageBeginMoving() {

showScrollingIndicator(false);

showScreenBubbleView(false);

}

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港