Java Code Examples for android.support.design.widget.CoordinatorLayout#LayoutParams
The following examples show how to use
android.support.design.widget.CoordinatorLayout#LayoutParams .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnimationViewBehaviorTest.java From simple-view-behavior with MIT License | 6 votes |
@Test public void animations() { ScaleAnimation animation = new ScaleAnimation(1f, 0f, 1f, 0f); AnimationViewBehavior behavior = new AnimationViewBehavior.Builder() .dependsOn(firstView.getId(), SimpleViewBehavior.DEPEND_TYPE_Y) .targetValue(100) .animation(animation) .build(); CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(320, 200); params.setBehavior(behavior); secondView.setLayoutParams(params); ShadowAnimation shadowAnimation = Shadow.extract(animation); firstView.setY(50); coordinatorLayout.requestLayout(); assertEquals(500L, shadowAnimation.getLastTimeGetTransform()); firstView.setY(100); coordinatorLayout.requestLayout(); assertEquals(1000L, shadowAnimation.getLastTimeGetTransform()); }
Example 2
Source File: MainActivity.java From NewsApp with GNU General Public License v3.0 | 6 votes |
@Override public void onSaveToggle(String text) { if (snackbar == null) { snackbar = Snackbar.make(binding.coordinator, "Hello", Snackbar.LENGTH_SHORT); final CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) snackbar.getView().getLayoutParams(); params.setMargins( (int) getResources().getDimension(R.dimen.snackbar_margin_vertical), 0, (int) getResources().getDimension(R.dimen.snackbar_margin_vertical), (int) getResources().getDimension(R.dimen.snackbar_margin_horizontal) ); snackbar.getView().setLayoutParams(params); snackbar.getView().setPadding( (int) getResources().getDimension(R.dimen.snackbar_padding), (int) getResources().getDimension(R.dimen.snackbar_padding), (int) getResources().getDimension(R.dimen.snackbar_padding), (int) getResources().getDimension(R.dimen.snackbar_padding) ); } if (snackbar.isShown()) { snackbar.dismiss(); } snackbar.setText(text); snackbar.show(); }
Example 3
Source File: HeaderScrollingViewBehavior.java From CoordinatorLayoutExample with Apache License 2.0 | 6 votes |
@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; } }
Example 4
Source File: SimpleViewBehaviorTest.java From simple-view-behavior with MIT License | 6 votes |
@Test public void targetAlpha() { SimpleViewBehavior behavior = new SimpleViewBehavior.Builder() .dependsOn(firstView.getId(), SimpleViewBehavior.DEPEND_TYPE_Y) .targetValue(100) .targetAlpha(0) .build(); CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(320, 200); params.setBehavior(behavior); secondView.setLayoutParams(params); // move first view by 100% firstView.setY(100); coordinatorLayout.requestLayout(); assertEquals(0f, secondView.getAlpha()); }
Example 5
Source File: CoordinatorLayoutUtil.java From PainlessMusicPlayer with Apache License 2.0 | 6 votes |
public static void clearAnchorGravityAndApplyMargins(@NonNull final View view) { final ViewGroup parent = (ViewGroup) view.getParent(); if (parent instanceof CoordinatorLayout) { final Rect rect = new Rect(); parent.getChildVisibleRect(view, rect, null); final ViewGroup.LayoutParams lp = view.getLayoutParams(); if (lp instanceof CoordinatorLayout.LayoutParams) { ((CoordinatorLayout.LayoutParams) lp).anchorGravity = 0; ((CoordinatorLayout.LayoutParams) lp).setAnchorId(0); ((CoordinatorLayout.LayoutParams) lp).setMargins(rect.left, rect.top, ((CoordinatorLayout.LayoutParams) lp).rightMargin, ((CoordinatorLayout.LayoutParams) lp).bottomMargin); } } }
Example 6
Source File: ImageStreamUi.java From belvedere with Apache License 2.0 | 6 votes |
private void initToolbar(final boolean fullScreenOnly) { toolbar.setNavigationIcon(R.drawable.belvedere_ic_close); toolbar.setNavigationContentDescription(R.string.belvedere_toolbar_desc_collapse); toolbar.setBackgroundColor(Color.WHITE); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(!fullScreenOnly) { bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); } else { dismiss(); } } }); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { toolbarCompatShadow.setVisibility(View.VISIBLE); } CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) toolbarContainer.getLayoutParams(); if(layoutParams != null) { layoutParams.setBehavior(new ToolbarBehavior(!fullScreenOnly)); } }
Example 7
Source File: PercentageViewBehaviorTest.java From simple-view-behavior with MIT License | 6 votes |
@Test public void dependsOnX() { SimpleViewBehavior behavior = new SimpleViewBehavior.Builder() .dependsOn(firstView.getId(), SimpleViewBehavior.DEPEND_TYPE_X) .targetValue(100) .targetX(100) .targetY(200) .build(); CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(320, 200); params.setBehavior(behavior); secondView.setLayoutParams(params); // move first view by 50% firstView.setX(50); coordinatorLayout.requestLayout(); assertEquals(0.5f, secondView.getCurrentPercent()); }
Example 8
Source File: PercentageViewBehaviorTest.java From simple-view-behavior with MIT License | 6 votes |
@Test public void dependsOnWidth() { SimpleViewBehavior behavior = new SimpleViewBehavior.Builder() .dependsOn(firstView.getId(), SimpleViewBehavior.DEPEND_TYPE_WIDTH) .targetValue(160) .targetX(100) .targetY(200) .build(); CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(320, 200); params.setBehavior(behavior); secondView.setLayoutParams(params); // resize first view's width CoordinatorLayout.LayoutParams resizeParams = new CoordinatorLayout.LayoutParams(firstView.getLayoutParams()); resizeParams.width = 160; firstView.setLayoutParams(resizeParams); coordinatorLayout.requestLayout(); assertEquals(1.0f, secondView.getCurrentPercent()); }
Example 9
Source File: ScrollingAppBarLayoutManager.java From react-native-bottom-sheet-behavior with MIT License | 5 votes |
@ReactProp(name = "translucent") public void setTranslucent(AppBarLayout view, boolean translucent) { if (Build.VERSION.SDK_INT >= 21 && translucent) { int statusBarHeight = getStatusBarHeight(view.getContext()); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) view.getLayoutParams(); params.setMargins(0, statusBarHeight, 0, 0); } }
Example 10
Source File: ChallengeActivity.java From BrainPhaser with GNU General Public License v3.0 | 5 votes |
/** * Loads the finish screen and unloads all other screens */ private void loadFinishScreen() { // Remove anchor by resetting layout params since anchor element has been removed from the screen CoordinatorLayout.LayoutParams lp = new CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.WRAP_CONTENT, CoordinatorLayout.LayoutParams.WRAP_CONTENT); mFloatingActionButton.setLayoutParams(lp); mFloatingActionButton.setVisibility(View.INVISIBLE); NestedScrollView contentLayout = (NestedScrollView) findViewById(R.id.challenge_rootcontainer); if (contentLayout != null) { contentLayout.removeAllViews(); View view = getLayoutInflater().inflate(R.layout.fragment_finish_challenge, contentLayout, false); contentLayout.addView(view); } }
Example 11
Source File: UcNewsTitleBehavior.java From CoordinatorLayoutExample with Apache License 2.0 | 5 votes |
@Override public boolean onLayoutChild(CoordinatorLayout parent, View child, int layoutDirection) { // FIXME: 16/7/27 不知道为啥在XML设置-45dip,解析出来的topMargin少了1个px,所以这里用代码设置一遍 ((CoordinatorLayout.LayoutParams) child.getLayoutParams()).topMargin = -getTitleHeight(); parent.onLayoutChild(child, layoutDirection); if (BuildConfig.DEBUG) { Log.d(TAG, "layoutChild:top" + child.getTop() + ",height" + child.getHeight()); } return true; }
Example 12
Source File: AmapRouteFragment.java From BmapLite with Apache License 2.0 | 5 votes |
private void configMap() { ConfigInteracter configInteracter = new ConfigInteracter(getActivity()); mAmap.getUiSettings().setScaleControlsEnabled(configInteracter.isShowScaleControl()); mAmap.getUiSettings().setZoomGesturesEnabled(configInteracter.isZoomGesturesEnabled()); mAmap.getUiSettings().setTiltGesturesEnabled(configInteracter.isOverlookEnable()); mAmap.getUiSettings().setRotateGesturesEnabled(configInteracter.isRotateEnable()); mAmap.setTrafficEnabled(configInteracter.isTrafficEnable()); mAmap.getUiSettings().setZoomControlsEnabled(false); mAmap.getUiSettings().setIndoorSwitchEnabled(false); if (configInteracter.getNightMode() == 2){ mAmap.setMapType(AMap.MAP_TYPE_NIGHT); }else { mAmap.setMapType(AMap.MAP_TYPE_NORMAL); } CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); if (configInteracter.getZoomControlsPosition()) { params.rightMargin = AppUtils.dip2Px(getActivity(), 10); params.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT; } else { params.leftMargin = AppUtils.dip2Px(getActivity(), 10); params.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; } mCardZoom.setLayoutParams(params); CoordinatorLayout.LayoutParams params3 = new CoordinatorLayout.LayoutParams(AppUtils.dip2Px(getActivity(), 40), AppUtils.dip2Px(getActivity(), 40)); params3.leftMargin = AppUtils.dip2Px(getActivity(), 10); params3.topMargin = AppUtils.dip2Px(getActivity(), 10); mImageCompass.setLayoutParams(params3); }
Example 13
Source File: GoogleMapsBottomSheetBehavior.java From Google-Maps-BottomSheet with The Unlicense | 5 votes |
/** * Anchor a view to the top of the bottomsheet/parallax. * @throws IllegalStateException when the view given does not have * {@link android.view.ViewGroup.LayoutParams} of type {@link CoordinatorLayout.LayoutParams} * @param view View to be anchored. */ public void anchorView(View view) { if (!(view.getLayoutParams() instanceof CoordinatorLayout.LayoutParams)) { throw new IllegalStateException("View must be a child of a CoordinatorLayout"); } anchoredViews.add(view); }
Example 14
Source File: WeiboSampleActivity.java From CoordinatorLayoutExample with Apache License 2.0 | 5 votes |
@Override protected void initData(Bundle savedInstanceState) { super.initData(savedInstanceState); setupViewPager(); CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) mHeaderView.getLayoutParams(); mHeaderPagerBehavior = (WeiboHeaderPagerBehavior) layoutParams.getBehavior(); mHeaderPagerBehavior.setPagerStateListener(this); }
Example 15
Source File: RNBottomSheetBehavior.java From react-native-bottom-sheet-behavior with MIT License | 5 votes |
/** * A utility function to get the {@link RNBottomSheetBehavior} associated with the {@code view}. * * @param view The {@link View} with {@link RNBottomSheetBehavior}. * @return The {@link RNBottomSheetBehavior} associated with the {@code view}. */ @SuppressWarnings("unchecked") public static <V extends View> RNBottomSheetBehavior<V> from(V view) { ViewGroup.LayoutParams params = view.getLayoutParams(); if (!(params instanceof CoordinatorLayout.LayoutParams)) { throw new IllegalArgumentException("The view is not a child of CoordinatorLayout"); } CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) params) .getBehavior(); if (!(behavior instanceof RNBottomSheetBehavior)) { throw new IllegalArgumentException( "The view is not associated with RNBottomSheetBehavior"); } return (RNBottomSheetBehavior<V>) behavior; }
Example 16
Source File: ImagesPagerFragment.java From MultiImagePicker with MIT License | 5 votes |
private void removeBehaviorAttr(final ViewGroup container) { //If the behavior hasn't been removed then when collapsing the toolbar the layout will resize which is annoying final CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) container.getLayoutParams(); layoutParams.setBehavior(null); container.setLayoutParams(layoutParams); }
Example 17
Source File: MainActivity.java From Anecdote with Apache License 2.0 | 5 votes |
@Subscribe public void changeFullscreenVisibilityEvent(ChangeFullscreenEvent event) { if (event.toFullscreen && getSupportActionBar() != null) { getSupportActionBar().hide(); // mAppBarLayout.animate().translationY(-mAppBarLayout.getBottom()).setInterpolator(new AccelerateInterpolator()).start(); } else if (getSupportActionBar() != null) { getSupportActionBar().show(); // mAppBarLayout.animate().translationY(0).setInterpolator(new AccelerateInterpolator()).start(); } new Handler().postDelayed(new Runnable() { @Override public void run() { mAppBarLayout.getParent().requestLayout(); } }, 600); if (event.toFullscreen) { // Hide status bar this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Remove the layout behavior on fragment container to prevent issue with the fullscreen CoordinatorLayout.LayoutParams fragmentContainerLayoutParams = (CoordinatorLayout.LayoutParams) mFragmentContainer.getLayoutParams(); mFragmentLayoutBehavior = fragmentContainerLayoutParams.getBehavior(); fragmentContainerLayoutParams.setBehavior(null); } else { // Show status bar getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); // Set back the layout behavior on fragment container ((CoordinatorLayout.LayoutParams) mFragmentContainer.getLayoutParams()) .setBehavior(new AppBarLayout.ScrollingViewBehavior()); } }
Example 18
Source File: AvatarImageBehavior.java From stynico with MIT License | 5 votes |
@Override public boolean onDependentViewChanged(CoordinatorLayout parent, CircleImageView child, View dependency) { CoordinatorLayout.LayoutParams lp= (CoordinatorLayout.LayoutParams) child.getLayoutParams(); int maxNumber= (int) (mMarginTop-getStatusBarHeight()); float percentageFactor = dependency.getY() / maxNumber; int proportionalAvatarSize = (int) (mMaxAvatarSize * (percentageFactor)); float childMarginTop = dependency.getY() - (child.getHeight() /2+20); float childMarginLeft = (dependency.getWidth() / 2) - (child.getWidth() / 2); float pChildMarginLeft = childMarginLeft * percentageFactor; int extraFinalPadding = (int) (EXTRA_FINAL_AVATAR_PADDING * (1f - percentageFactor)); if (percentageFactor >= MIN_AVATAR_PERCETAGE_SIZE) { lp.width = proportionalAvatarSize; lp.height = proportionalAvatarSize; } lp.setMargins( (int) pChildMarginLeft + extraFinalPadding, (int) childMarginTop + extraFinalPadding, lp.rightMargin, lp.bottomMargin ); child.setLayoutParams(lp); return true; }
Example 19
Source File: MainActivity.java From v9porn with MIT License | 5 votes |
private void hideFloatingActionButton(FloatingActionButton fabSearch) { ViewGroup.LayoutParams layoutParams = fabSearch.getLayoutParams(); if (layoutParams instanceof CoordinatorLayout.LayoutParams) { CoordinatorLayout.LayoutParams coLayoutParams = (CoordinatorLayout.LayoutParams) layoutParams; FloatingActionButton.Behavior behavior = new FloatingActionButton.Behavior(); coLayoutParams.setBehavior(behavior); } fabSearch.hide(); }
Example 20
Source File: BottomSheetBehaviorV2.java From paper-launcher with MIT License | 5 votes |
/** * A utility function to get the {@link BottomSheetBehaviorV2} associated with the {@code view}. * * @param view The {@link View} with {@link BottomSheetBehaviorV2}. * @return The {@link BottomSheetBehaviorV2} associated with the {@code view}. */ @SuppressWarnings("unchecked") public static <V extends View> BottomSheetBehaviorV2<V> from(V view) { ViewGroup.LayoutParams params = view.getLayoutParams(); if (!(params instanceof CoordinatorLayout.LayoutParams)) { throw new IllegalArgumentException("The view is not a child of CoordinatorLayout"); } CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) params) .getBehavior(); if (!(behavior instanceof BottomSheetBehaviorV2)) { throw new IllegalArgumentException( "The view is not associated with BottomSheetBehavior"); } return (BottomSheetBehaviorV2<V>) behavior; }