DevStore首页 > DEV资源 > 源码下载 > 源码详情

TestCoordinatorLayout

 
KellyZong | 2017-03-14 09:44    浏览量(664)    评论(0)    收藏(1)
功能分类:特效 支持平台:Android 运行环境:Android
开发语言:Java 开发工具:Android Studio 源码大小:92.71MB
下载源码 28 人下载

源码简介

A CoordinatorLayout demo for studying it.And it coded with listView combined with beheavior definited by myself.(结合listView自定义beheavior实现的CoordinatorLayout的测试demo); CoordinatorLayout结合自定义beheavior,listView的使用, listView作为toorBar的anchor,CircleImageView依赖toorBar, 利用自定义的CircleImageView的beheavior实现:滑动listView时,toorBar和CircleImageView随着分别渐隐渐现和放大缩小等效果。

源码截图

DevStore所有源码来自用户上传分享,版权问题及牵扯到商业纠纷均与DevStore无关。

源码片段

github:
https://github.com/zongkaili/TestCoordinatorLayout

###关键代码:

 - 设置自动滑动的动画效果
 ```java
    private void initParallaxValues() {
        CollapsingToolbarLayout.LayoutParams petDetailsLp =
                (CollapsingToolbarLayout.LayoutParams) mIvPlaceholder.getLayoutParams();

        CollapsingToolbarLayout.LayoutParams petBackgroundLp =
                (CollapsingToolbarLayout.LayoutParams) mFlTitleContainer.getLayoutParams();

        petDetailsLp.setParallaxMultiplier(0.9f);
        petBackgroundLp.setParallaxMultiplier(0.3f);

        mIvPlaceholder.setLayoutParams(petDetailsLp);
        mFlTitleContainer.setLayoutParams(petBackgroundLp);
    }
```
 - 处理ToolBar的显示
 ```java
    private void handleToolbarTitleVisibility(float percentage) {
            if (percentage >= PERCENTAGE_TO_SHOW_TITLE_AT_TOOLBAR) {
                if (!mIsTheTitleVisible) {
                    startAlphaAnimation(mTbToolbar, ALPHA_ANIMATIONS_DURATION, View.VISIBLE);
                    mIsTheTitleVisible = true;
                }
            } else {
                if (mIsTheTitleVisible) {
                    startAlphaAnimation(mTbToolbar, ALPHA_ANIMATIONS_DURATION, View.INVISIBLE);
                    mIsTheTitleVisible = false;
                    
                }
            }
        }
 ``` 
 - 设置渐变的动画
 ```java
    public static void startAlphaAnimation(View v, long duration, int visibility) {
            AlphaAnimation alphaAnimation = (visibility == View.VISIBLE)
                    ? new AlphaAnimation(0f, 1f)
                    : new AlphaAnimation(1f, 0f);
    
            alphaAnimation.setDuration(duration);
            alphaAnimation.setFillAfter(true);
            v.startAnimation(alphaAnimation);
    }
 ``` 
 - 控制titleBar下面的View的隐藏显示
 ```java
      @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
             int top = getYLocationOnScreen(mLlQTSwitcher);
             Log.d(TAG, "top : " + top + " location1[1] : " + getYLocationOnScreen(mLlQTSwitcher) + " location2[1] : " + getYLocationOnScreen(mRlTitleBarShadow));
     
             Log.d(TAG," mLlQTSwitcher.getY() : " + mLlQTSwitcher.getY()+" getYLocationOnScreen(mTbToolbar) : " + getYLocationOnScreen(mLlQTSwitcher));
                 if (getYLocationOnScreen(mTbToolbar) == CommonUtils.getStatusBarHeight(this) && (top < getYLocationOnScreen(mRlTitleBarShadow) || firstVisibleItem >= 1)) {
                     mRlTitleBarShadow.setVisibility(View.VISIBLE);
                 } else {
                     mRlTitleBarShadow.setVisibility(View.GONE);
                 }
    }
  •   赞(1) 赞 +1 赞(1) 已赞
  •   收藏(1) 收藏 +1 已收藏 取消
  •   下载(28)
评论(0)
  • 推荐
  • 审核
  • 收录
  • 获取活力值

源码上传作者

  • 4 能力值
  • 2 源码
  • 0 评测
  • 0 资料