當前位置: 首頁>>代碼示例>>Java>>正文


Java CoordinatorLayout類代碼示例

本文整理匯總了Java中android.support.design.widget.CoordinatorLayout的典型用法代碼示例。如果您正苦於以下問題:Java CoordinatorLayout類的具體用法?Java CoordinatorLayout怎麽用?Java CoordinatorLayout使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CoordinatorLayout類屬於android.support.design.widget包,在下文中一共展示了CoordinatorLayout類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onNestedScroll

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child,
                           View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed,
            dyUnconsumed);

    if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
        child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
            @Override
            public void onHidden(FloatingActionButton fab) {
                super.onShown(fab);
                fab.setVisibility(View.INVISIBLE);
            }
        });
    } else if (dyConsumed < 0){
        child.show();
    }
}
 
開發者ID:ndleyton,項目名稱:OneTwo,代碼行數:19,代碼來源:ScrollAwareFABBehavior.java

示例2: getFabTranslationYForBottomNavigationBar

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
private float[] getFabTranslationYForBottomNavigationBar(CoordinatorLayout parent,
                                                         FloatingActionButton fab) {
    float minOffset = 0;
    float viewHeight = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof BottomNavigationBar) {
            viewHeight = view.getHeight();
            minOffset = Math.min(minOffset,
                    ViewCompat.getTranslationY(view) - viewHeight);
        }
    }
    float[] returnValues = {minOffset, viewHeight};

    return returnValues;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:BottomNavBarFabBehaviour.java

示例3: onNestedScroll

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
@Override
public void onNestedScroll(final CoordinatorLayout coordinatorLayout, final
FloatingActionButton child, final View target, final int dxConsumed, final int dyConsumed,
                           final int dxUnconsumed, final int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed,
            dxUnconsumed, dyUnconsumed);
    if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
        /** design lib 升級到 25.1.0 導致 child.hide() 效果失效,法克喲
         *  http://stackoverflow.com/questions/41761736/android-design-library-25-1-0-causes-floatingactionbutton-behavior-to-stop-worki
         */
        child.hide(new FloatingActionButton.OnVisibilityChangedListener() {
            @Override
            public void onHidden(FloatingActionButton fab) {
                super.onHidden(fab);
                fab.setVisibility(View.INVISIBLE);
            }
        });
    } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
        child.show();
    }
}
 
開發者ID:li-yu,項目名稱:Huahui-Android,代碼行數:22,代碼來源:FloatingActionButtonScrollBehavior.java

示例4: updateSnackbar

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
@Override
public void updateSnackbar(CoordinatorLayout parent, View dependency, View child) {
    if (dependency instanceof Snackbar.SnackbarLayout) {
        if (mSnackbarHeight == -1) {
            mSnackbarHeight = dependency.getHeight();
        }

        int targetPadding = child.getMeasuredHeight();

        int shadow = (int) ViewCompat.getElevation(child);
        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) dependency.getLayoutParams();
        layoutParams.bottomMargin = targetPadding - shadow;
        child.bringToFront();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            child.getParent().requestLayout();
            ((View) child.getParent()).invalidate();
        }

    }
}
 
開發者ID:homeii,項目名稱:GxIconAndroid,代碼行數:21,代碼來源:BottomNavigationBehavior.java

示例5: init

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
private void init(final CoordinatorLayout coordinatorLayout, final AppBarLayout child) {
  // disable dragCallback by default
  if (mDragCallbackListener == null) {
    mDragCallbackListener = new DragCallback() {

      @Override
      public boolean canDrag(AppBarLayout appBarLayout) {
        return false;
      }
    };
    setDragCallback(mDragCallbackListener);
  }

  // dispatch init event
  Utils.log("onInit");
  mCoordinatorLayout = coordinatorLayout;
  onInit(coordinatorLayout, child);
}
 
開發者ID:PacktPublishing,項目名稱:Expert-Android-Programming,代碼行數:19,代碼來源:BaseBehavior.java

示例6: onNestedPreScroll

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
@Override
    public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) {
        super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed);

//        if (!mIsScrollToBottom) {
//            float mPreTranslationY = dy + child.getTranslationY();
//            if (mPreTranslationY <= 0) {
//                child.setTranslationY(0);
//                mIsAnimatingOut = true;
//            }
//            if (mPreTranslationY >= child.getHeight()) {
//                child.setTranslationY(child.getHeight());
//                mIsAnimatingOut = false;
//            }
//            if (mPreTranslationY > 0 && mPreTranslationY < child.getHeight()) {
//                child.setTranslationY(mPreTranslationY);
//                mIsAnimatingOut = dy > 0;
//            }
//        }
    }
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:21,代碼來源:FloatingAutoHideDownBehavior.java

示例7: onDependentViewChanged

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, SimpleDraweeView child, View dependency) {
    maybeInitProperties(child, dependency);

    final int maxScrollDistance = (int) (mStartToolbarPosition - getStatusBarHeight());
    float expandedPercentageFactor = dependency.getY() / maxScrollDistance;

    float distanceYToSubtract = ((mStartYPosition - mFinalYPosition)
            * (1f - expandedPercentageFactor)) + (child.getHeight()/2);

    float distanceXToSubtract = ((mStartXPosition - mFinalXPosition)
            * (1f - expandedPercentageFactor)) + (child.getWidth()/2);

    float heightToSubtract = ((mStartHeight - finalHeight) * (1f - expandedPercentageFactor));

    child.setY(mStartYPosition - distanceYToSubtract);
    child.setX(mStartXPosition - distanceXToSubtract);

    int proportionalAvatarSize = (int) (mAvatarMaxSize * (expandedPercentageFactor));

    CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
    lp.width = (int) (mStartHeight - heightToSubtract);
    lp.height = (int) (mStartHeight - heightToSubtract);
    child.setLayoutParams(lp);
    return true;
}
 
開發者ID:picopalette,項目名稱:event-me,代碼行數:27,代碼來源:ImageBehaviour.java

示例8: onNestedFling

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
@Override
public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target,
                             float velocityX, float velocityY, boolean consumed) {
    if (target instanceof RecyclerView && velocityY < 0) {
        Log.d(TAG, "onNestedFling: target is recyclerView");
        final RecyclerView recyclerView = (RecyclerView) target;
        final View firstChild = recyclerView.getChildAt(0);
        final int childAdapterPosition = recyclerView.getChildAdapterPosition(firstChild);
        consumed = childAdapterPosition > TOP_CHILD_FLING_THRESHOLD;
    }

    // prevent fling flickering when going up
    if (target instanceof NestedScrollView && velocityY > 0) {
        consumed = true;
    }

    if (Math.abs(velocityY) < OPTIMAL_FLING_VELOCITY) {
        velocityY = OPTIMAL_FLING_VELOCITY * (velocityY < 0 ? -1 : 1);
    }
    Log.d(TAG, "onNestedFling: velocityY - " + velocityY + ", consumed - " + consumed);

    return super.onNestedFling(coordinatorLayout, child, target, velocityX, velocityY, consumed);
}
 
開發者ID:funnyzhaov,項目名稱:Tribe,代碼行數:24,代碼來源:FlingBehavior.java

示例9: onNestedScroll

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
@Override
public void onNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton fab,
						   final View target, final int dxConsumed, final int dyConsumed,
						   final int dxUnconsumed, final int dyUnconsumed) {
	super.onNestedScroll(coordinatorLayout, fab, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
	if (!enabled) return;
	if (dyConsumed > 0 && fab.getVisibility() == View.VISIBLE) {
		// User scrolled down and the FAB is currently visible -> hide the FAB
		fab.hide();
	} else if (dyConsumed < 0 && fab.getVisibility() != View.VISIBLE) {
		// User scrolled up and the FAB is currently not visible -> show the FAB
		fab.postDelayed(new Runnable() {
			@Override
			public void run() {
				fab.show();
			}
		}, 200L);
	}
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:ScrollAwareFABBehavior.java

示例10: setBaseView

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
@Override
protected void setBaseView(@LayoutRes int layoutId) {
    Slidr.attach(this);
    contentView = LayoutInflater.from(this).inflate(R.layout.activity_back, null);
    setContentView(contentView);
    rootLayout = (CoordinatorLayout) findViewById(R.id.root_layout);
    abl = (AppBarLayout) findViewById(R.id.abl);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    flActivityContainer = (FrameLayout) findViewById(R.id.activity_container);
    flActivityContainer.addView(LayoutInflater.from(this).inflate(layoutId, flActivityContainer, false));
    setSupportActionBar(mToolbar);
    getToolBar().setDisplayHomeAsUpEnabled(true);

    BarUtils.setStatusBarColor(this, ContextCompat.getColor(UtilsApp.getInstance(), R.color.colorPrimary), 0);
    BarUtils.addMarginTopEqualStatusBarHeight(rootLayout);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:BaseBackActivity.java

示例11: showBottomLayout

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
/**
     * 點擊內容欄喚起底部操作區域
     *
     * @param coordinatorLayout 外部CoordinatorLayout
     * @param contentView       滾動區域
     * @param bottomView        滾動時隱藏底部區域
     */
    public static void showBottomLayout(CoordinatorLayout coordinatorLayout, View contentView, final View bottomView) {
        //coordinatorLayout.onStartNestedScroll(contentView, null, ViewCompat.SCROLL_AXIS_VERTICAL);
        //coordinatorLayout.onNestedPreScroll(bottomView, 0, -1, new int[2]);
        //coordinatorLayout.onStopNestedScroll(null);
//        bottomView.animate()
//                .translationY(0)
//                .setInterpolator(INTERPOLATOR)
//                .setDuration(200)
//                .setListener(new AnimatorListenerAdapter() {
//                    @Override
//                    public void onAnimationEnd(Animator animation) {
//                        bottomView.setTranslationY(0);
//                    }
//                });
    }
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:23,代碼來源:FloatingAutoHideDownBehavior.java

示例12: prepare

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
/** 初始化數據 */
private void prepare(CoordinatorLayout parent, View child, View dependency) {
    mDependStartX = (int) dependency.getX();
    mDependStartY = (int) dependency.getY();
    mDependStartWidth = dependency.getWidth();
    mDependStartHeight = dependency.getHeight();
    mStartX = (int) child.getX();
    mStartY = (int) child.getY();
    mStartWidth = child.getWidth();
    mStartHeight = child.getHeight();
    mStartAlpha = child.getAlpha();
    mStartRotateX = child.getRotationX();
    mStartRotateY = child.getRotationY();

    //特殊處理y方向變化
    if (mDependTargetY == UNSPECIFIED_INT && dependency instanceof AppBarLayout) {
        mDependTargetY = ((AppBarLayout) dependency).getTotalScrollRange();
    }
    // 背景顏色漸變
    if (child.getBackground() instanceof ColorDrawable) mStartBackgroundColor = ((ColorDrawable) child.getBackground()).getColor();
    // 自定義動畫
    if (mAnimationId != 0) {
        mAnimation = AnimationUtils.loadAnimation(child.getContext(), mAnimationId);
        mAnimation.initialize(child.getWidth(), child.getHeight(), parent.getWidth(), parent.getHeight());
    }
    // 兼容5.0以上的沉浸模式
    if (Build.VERSION.SDK_INT > 16 && parent.getFitsSystemWindows() && targetY != UNSPECIFIED_INT) {
        targetY += getStatusBarHeight(parent.getContext());
    }
    isPrepared = true;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:SimpleViewBehavior.java

示例13: onDependentViewChanged

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {

    //UCViewTab要滑動的距離為Header的高度減去TitleView的高度
    float offsetRange = mTitleViewHeight - dependency.getMeasuredHeight();
    //當Header向上滑動mTitleViewHeight高度後,即滑動完成
    int headerOffsetRange = -mTitleViewHeight;

    if(dependency.getTranslationY() == headerOffsetRange) {//Header已經上滑結束
        child.setTranslationY(offsetRange);
    } else if(dependency.getTranslationY() == 0) {//下滑結束,也是初始化的狀態
        child.setTranslationY(0);
    } else {
        //UCViewTab與UCViewHeader為同向滑動
        //根據依賴UCViewHeader的滑動比例計算當前UCViewTab應該要滑動的值translationY
        child.setTranslationY(dependency.getTranslationY() / (headerOffsetRange * 1.0f) * offsetRange);
    }
    return false;
}
 
開發者ID:huyongli,項目名稱:UCMainViewForBehavior,代碼行數:20,代碼來源:UCViewTabBehavior.java

示例14: layoutChild

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
@Override
protected void layoutChild(final CoordinatorLayout parent, final View child, final int layoutDirection) {
    final List<View> dependencies = parent.getDependencies(child);
    final View header = findFirstDependency(dependencies);

    if (header != null) {
        final CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
        final Rect available = mTempRect1;
        available.set(parent.getPaddingLeft() + lp.leftMargin, header.getBottom() + lp.topMargin,
                parent.getWidth() - parent.getPaddingRight() - lp.rightMargin,
                parent.getHeight() + header.getBottom() - parent.getPaddingBottom() - lp.bottomMargin);

        final Rect out = mTempRect2;
        GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), available, out, layoutDirection);

        final int overlap = getOverlapPixelsForOffset(header);

        child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap);
        mVerticalLayoutGap = out.top - header.getBottom();
    } else {
        // If we don't have a dependency, let super handle it
        super.layoutChild(parent, child, layoutDirection);
        mVerticalLayoutGap = 0;
    }
}
 
開發者ID:Learzhu,項目名稱:UcMainPagerDemo-master,代碼行數:26,代碼來源:HeaderScrollingViewBehavior.java

示例15: onCreateDialog

import android.support.design.widget.CoordinatorLayout; //導入依賴的package包/類
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog mSheet = super.onCreateDialog(savedInstanceState);
    View contentView = View.inflate(getContext(), R.layout.bottom_sheet_emoticons, null);
    mSheet.setContentView(contentView);

    unbinder = ButterKnife.bind(this, mSheet);

    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
    CoordinatorLayout.Behavior behavior = params.getBehavior();

    if (behavior != null && behavior instanceof BottomSheetBehavior) {
        bottomSheetBehavior = (BottomSheetBehavior) behavior;
        bottomSheetBehavior.setBottomSheetCallback(mBottomSheetBehaviorCallback);
    }

    onPostCreate(this);
    return mSheet;
}
 
開發者ID:wax911,項目名稱:anitrend-app,代碼行數:21,代碼來源:BottomSheetEmoticon.java


注:本文中的android.support.design.widget.CoordinatorLayout類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。