本文整理汇总了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();
}
}
示例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;
}
示例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();
}
}
示例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();
}
}
}
示例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);
}
示例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;
// }
// }
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
// }
// });
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}