List of usage examples for android.view Gravity TOP
int TOP
To view the source code for android.view Gravity TOP.
Click Source Link
From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java
/** * Close the specified drawer view by animating it into view. * //from w w w . jav a2 s .com * @param drawerView * Drawer view to close */ public void closeDrawer(View drawerView) { if (!isDrawerView(drawerView)) { throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer"); } if (mFirstLayout) { final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); lp.onScreen = 0.f; lp.knownOpen = false; } else { if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.TOP)) { mTopDragger.smoothSlideViewTo(drawerView, drawerView.getLeft(), -drawerView.getHeight()); } else { mBottomDragger.smoothSlideViewTo(drawerView, drawerView.getLeft(), getHeight()); } } invalidate(); }
From source file:android.support.design.widget.CoordinatorLayout.java
/** * Lay out a child view with respect to a keyline. * * <p>The keyline represents a horizontal offset from the unpadded starting edge of * the CoordinatorLayout. The child's gravity will affect how it is positioned with * respect to the keyline.</p>// w w w. j a v a 2 s . c om * * @param child child to lay out * @param keyline offset from the starting edge in pixels of the keyline to align with * @param layoutDirection ViewCompat constant for layout direction */ private void layoutChildWithKeyline(View child, int keyline, int layoutDirection) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int absGravity = GravityCompat.getAbsoluteGravity(resolveKeylineGravity(lp.gravity), layoutDirection); final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK; final int width = getWidth(); final int height = getHeight(); final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) { keyline = width - keyline; } int left = getKeyline(keyline) - childWidth; int top = 0; switch (hgrav) { default: case Gravity.LEFT: // Nothing to do. break; case Gravity.RIGHT: left += childWidth; break; case Gravity.CENTER_HORIZONTAL: left += childWidth / 2; break; } switch (vgrav) { default: case Gravity.TOP: // Do nothing, we're already in position. break; case Gravity.BOTTOM: top += childHeight; break; case Gravity.CENTER_VERTICAL: top += childHeight / 2; break; } // Obey margins and padding left = Math.max(getPaddingLeft() + lp.leftMargin, Math.min(left, width - getPaddingRight() - childWidth - lp.rightMargin)); top = Math.max(getPaddingTop() + lp.topMargin, Math.min(top, height - getPaddingBottom() - childHeight - lp.bottomMargin)); child.layout(left, top, left + childWidth, top + childHeight); }
From source file:com.gome.ecmall.custom.VerticalViewPager.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // For simple implementation, or internal size is always 0. // We depend on the container to specify the layout size of // our view. We can't really know what it is since we will be // adding and removing different arbitrary views and do not // want the layout to change as this happens. setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec)); // final int measuredWidth = getMeasuredWidth(); final int measuredHeight = getMeasuredHeight(); final int maxGutterSize = measuredHeight / 10; mGutterSize = Math.min(maxGutterSize, mDefaultGutterSize); // Children are just made to fill our space. // int childWidthSize = measuredWidth - getPaddingLeft() // - getPaddingRight(); // int childHeightSize = getMeasuredHeight() - getPaddingTop() // - getPaddingBottom(); int childWidthSize = getMeasuredWidth() - getPaddingLeft() - getPaddingRight(); int childHeightSize = measuredHeight - getPaddingTop() - getPaddingBottom(); /*//from w ww . jav a 2s.co m * Make sure all children have been properly measured. Decor views first. Right now we cheat and make this less * complicated by assuming decor views won't intersect. We will pin to edges based on gravity. */ int size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp != null && lp.isDecor) { final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; int widthMode = MeasureSpec.AT_MOST; int heightMode = MeasureSpec.AT_MOST; boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM; boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT; if (consumeVertical) { widthMode = MeasureSpec.EXACTLY; } else if (consumeHorizontal) { heightMode = MeasureSpec.EXACTLY; } int widthSize = childWidthSize; int heightSize = childHeightSize; if (lp.width != LayoutParams.WRAP_CONTENT) { widthMode = MeasureSpec.EXACTLY; if (lp.width != LayoutParams.MATCH_PARENT) { widthSize = lp.width; } } if (lp.height != LayoutParams.WRAP_CONTENT) { heightMode = MeasureSpec.EXACTLY; if (lp.height != LayoutParams.MATCH_PARENT) { heightSize = lp.height; } } final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode); final int heightSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode); child.measure(widthSpec, heightSpec); if (consumeVertical) { childHeightSize -= child.getMeasuredHeight(); } else if (consumeHorizontal) { childWidthSize -= child.getMeasuredWidth(); } } } } mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY); mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY); // Make sure we have created all fragments that we need to have shown. mInLayout = true; populate(); mInLayout = false; // Page views next. size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { if (DEBUG) Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp == null || !lp.isDecor) { // final int widthSpec = MeasureSpec.makeMeasureSpec( // (int) (childWidthSize * lp.heightFactor), // MeasureSpec.EXACTLY); final int heightSpec = MeasureSpec.makeMeasureSpec((int) (childHeightSize * lp.heightFactor), MeasureSpec.EXACTLY); child.measure(mChildWidthMeasureSpec, heightSpec); } } } }
From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java
/** * Start transition to expand or collapse GuidedActionStylist. * @param avh When not null, the GuidedActionStylist expands the sub actions of avh. When null * the GuidedActionStylist will collapse sub actions. *//*from ww w. j a v a 2 s. c o m*/ public void startExpandedTransition(ViewHolder avh) { ViewHolder focusAvh = null; // expand / collapse view holder final int count = mActionsGridView.getChildCount(); for (int i = 0; i < count; i++) { ViewHolder vh = (ViewHolder) mActionsGridView.getChildViewHolder(mActionsGridView.getChildAt(i)); if (avh == null && vh.itemView.getVisibility() == View.VISIBLE) { // going to collapse this one. focusAvh = vh; break; } else if (avh != null && vh.getAction() == avh.getAction()) { // going to expand this one. focusAvh = vh; break; } } if (focusAvh == null) { // huh? onUpdateExpandedViewHolder(avh); return; } boolean isSubActionTransition = focusAvh.getAction().hasSubActions(); Object set = TransitionHelper.createTransitionSet(false); float slideDistance = isSubActionTransition ? focusAvh.itemView.getHeight() : focusAvh.itemView.getHeight() * 0.5f; Object slideAndFade = TransitionHelper.createFadeAndShortSlide(Gravity.TOP | Gravity.BOTTOM, slideDistance); Object changeFocusItemTransform = TransitionHelper.createChangeTransform(); Object changeFocusItemBounds = TransitionHelper.createChangeBounds(false); Object fade = TransitionHelper.createFadeTransition(TransitionHelper.FADE_IN | TransitionHelper.FADE_OUT); Object changeGridBounds = TransitionHelper.createChangeBounds(false); if (avh == null) { TransitionHelper.setStartDelay(slideAndFade, 150); TransitionHelper.setStartDelay(changeFocusItemTransform, 100); TransitionHelper.setStartDelay(changeFocusItemBounds, 100); } else { TransitionHelper.setStartDelay(fade, 100); TransitionHelper.setStartDelay(changeGridBounds, 100); TransitionHelper.setStartDelay(changeFocusItemTransform, 50); TransitionHelper.setStartDelay(changeFocusItemBounds, 50); } for (int i = 0; i < count; i++) { ViewHolder vh = (ViewHolder) mActionsGridView.getChildViewHolder(mActionsGridView.getChildAt(i)); if (vh == focusAvh) { // going to expand/collapse this one. if (isSubActionTransition) { TransitionHelper.include(changeFocusItemTransform, vh.itemView); TransitionHelper.include(changeFocusItemBounds, vh.itemView); } } else { // going to slide this item to top / bottom. TransitionHelper.include(slideAndFade, vh.itemView); TransitionHelper.exclude(fade, vh.itemView, true); } } TransitionHelper.include(changeGridBounds, mSubActionsGridView); TransitionHelper.addTransition(set, slideAndFade); // note that we don't run ChangeBounds for activating view due to the rounding problem // of multiple level views ChangeBounds animation causing vertical jittering. if (isSubActionTransition) { TransitionHelper.addTransition(set, changeFocusItemTransform); TransitionHelper.addTransition(set, changeFocusItemBounds); } TransitionHelper.addTransition(set, fade); TransitionHelper.addTransition(set, changeGridBounds); mExpandTransition = set; TransitionHelper.addTransitionListener(mExpandTransition, new TransitionListener() { @Override public void onTransitionEnd(Object transition) { mExpandTransition = null; } }); if (avh != null && mSubActionsGridView.getTop() != avh.itemView.getTop()) { // For expanding, set the initial position of subActionsGridView before running // a ChangeBounds on it. final ViewHolder toUpdate = avh; mSubActionsGridView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if (mSubActionsGridView == null) { return; } mSubActionsGridView.removeOnLayoutChangeListener(this); mMainView.post(new Runnable() { public void run() { if (mMainView == null) { return; } TransitionHelper.beginDelayedTransition(mMainView, mExpandTransition); onUpdateExpandedViewHolder(toUpdate); } }); } }); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mSubActionsGridView.getLayoutParams(); lp.topMargin = avh.itemView.getTop(); lp.height = 0; mSubActionsGridView.setLayoutParams(lp); return; } TransitionHelper.beginDelayedTransition(mMainView, mExpandTransition); onUpdateExpandedViewHolder(avh); }
From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
@Override protected void onRestoreInstanceState(Parcelable state) { final SavedState ss = (SavedState) state; super.onRestoreInstanceState(ss.getSuperState()); if (ss.openDrawerGravity != Gravity.NO_GRAVITY) { final View toOpen = findDrawerWithGravity(ss.openDrawerGravity); if (toOpen != null) { openDrawer(toOpen);/*from ww w.jav a 2 s . co m*/ } } setDrawerLockMode(ss.lockModeTop, Gravity.TOP); setDrawerLockMode(ss.lockModeBottom, Gravity.BOTTOM); }
From source file:com.rbware.github.androidcouchpotato.widget.GuidedActionsStylist.java
/** * Start transition to expand or collapse GuidedActionStylist. * @param avh When not null, the GuidedActionStylist expands the sub actions of avh. When null * the GuidedActionStylist will collapse sub actions. *///from w w w. ja v a2 s. c o m public void startExpandedTransition(ViewHolder avh) { ViewHolder focusAvh = null; // expand / collapse view holder final int count = mActionsGridView.getChildCount(); for (int i = 0; i < count; i++) { ViewHolder vh = (ViewHolder) mActionsGridView.getChildViewHolder(mActionsGridView.getChildAt(i)); if (avh == null && vh.itemView.getVisibility() == View.VISIBLE) { // going to collapse this one. focusAvh = vh; break; } else if (avh != null && vh.getAction() == avh.getAction()) { // going to expand this one. focusAvh = vh; break; } } if (focusAvh == null) { // huh? onUpdateExpandedViewHolder(avh); return; } boolean isSubActionTransition = focusAvh.getAction().hasSubActions(); Object set = TransitionHelper.createTransitionSet(false); float slideDistance = isSubActionTransition ? focusAvh.itemView.getHeight() : focusAvh.itemView.getHeight() * 0.5f; Object slideAndFade = TransitionHelper.createFadeAndShortSlide(Gravity.TOP | Gravity.BOTTOM, slideDistance); Object changeFocusItemTransform = TransitionHelper.createChangeTransform(); Object changeFocusItemBounds = TransitionHelper.createChangeBounds(false); Object fade = TransitionHelper.createFadeTransition(TransitionHelper.FADE_IN | TransitionHelper.FADE_OUT); Object changeGridBounds = TransitionHelper.createChangeBounds(false); if (avh == null) { TransitionHelper.setStartDelay(slideAndFade, 150); TransitionHelper.setStartDelay(changeFocusItemTransform, 100); TransitionHelper.setStartDelay(changeFocusItemBounds, 100); } else { TransitionHelper.setStartDelay(fade, 100); TransitionHelper.setStartDelay(changeGridBounds, 100); TransitionHelper.setStartDelay(changeFocusItemTransform, 50); TransitionHelper.setStartDelay(changeFocusItemBounds, 50); } for (int i = 0; i < count; i++) { ViewHolder vh = (ViewHolder) mActionsGridView.getChildViewHolder(mActionsGridView.getChildAt(i)); if (vh == focusAvh) { // going to expand/collapse this one. if (isSubActionTransition) { TransitionHelper.include(changeFocusItemTransform, vh.itemView); TransitionHelper.include(changeFocusItemBounds, vh.itemView); } } else { // going to slide this item to top / bottom. TransitionHelper.include(slideAndFade, vh.itemView); TransitionHelper.exclude(fade, vh.itemView, true); } } TransitionHelper.include(changeGridBounds, mSubActionsGridView); TransitionHelper.include(changeGridBounds, mSubActionsBackground); TransitionHelper.addTransition(set, slideAndFade); // note that we don't run ChangeBounds for activating view due to the rounding problem // of multiple level views ChangeBounds animation causing vertical jittering. if (isSubActionTransition) { TransitionHelper.addTransition(set, changeFocusItemTransform); TransitionHelper.addTransition(set, changeFocusItemBounds); } TransitionHelper.addTransition(set, fade); TransitionHelper.addTransition(set, changeGridBounds); mExpandTransition = set; TransitionHelper.addTransitionListener(mExpandTransition, new TransitionListener() { @Override public void onTransitionEnd(Object transition) { mExpandTransition = null; } }); if (avh != null && mSubActionsGridView.getTop() != avh.itemView.getTop()) { // For expanding, set the initial position of subActionsGridView before running // a ChangeBounds on it. final ViewHolder toUpdate = avh; mSubActionsGridView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if (mSubActionsGridView == null) { return; } mSubActionsGridView.removeOnLayoutChangeListener(this); mMainView.post(new Runnable() { @Override public void run() { if (mMainView == null) { return; } TransitionHelper.beginDelayedTransition(mMainView, mExpandTransition); onUpdateExpandedViewHolder(toUpdate); } }); } }); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mSubActionsGridView.getLayoutParams(); lp.topMargin = avh.itemView.getTop(); lp.height = 0; mSubActionsGridView.setLayoutParams(lp); return; } TransitionHelper.beginDelayedTransition(mMainView, mExpandTransition); onUpdateExpandedViewHolder(avh); }
From source file:android.support.design.widget.CoordinatorLayout.java
/** * Return the given gravity value, but if either or both of the axes doesn't have any gravity * specified, the default value (start or top) is specified. This should be used for children * that are not anchored to another view or a keyline. *//* w w w . ja va 2 s . c o m*/ private static int resolveGravity(int gravity) { if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.NO_GRAVITY) { gravity |= GravityCompat.START; } if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.NO_GRAVITY) { gravity |= Gravity.TOP; } return gravity; }
From source file:com.jackie.sample.custom_view.CustomViewPagerInternal.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // For simple implementation, or internal size is always 0. // We depend on the container to specify the layout size of // our view. We can't really know what it is since we will be // adding and removing different arbitrary views and do not // want the layout to change as this happens. setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec)); final int measuredWidth = getMeasuredWidth(); final int maxGutterSize = measuredWidth / 10; mGutterSize = Math.min(maxGutterSize, mDefaultGutterSize); // ChildrenBean are just made to fill our space. int childWidthSize = measuredWidth - getPaddingLeft() - getPaddingRight(); int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom(); /*//from ww w . java2s . c om * Make sure all children have been properly measured. Decor views first. * Right now we cheat and make this less complicated by assuming decor * views won't intersect. We will pin to edges based on gravity. */ int size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp != null && lp.isDecor) { final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; int widthMode = MeasureSpec.AT_MOST; int heightMode = MeasureSpec.AT_MOST; boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM; boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT; if (consumeVertical) { widthMode = MeasureSpec.EXACTLY; } else if (consumeHorizontal) { heightMode = MeasureSpec.EXACTLY; } int widthSize = childWidthSize; int heightSize = childHeightSize; if (lp.width != LayoutParams.WRAP_CONTENT) { widthMode = MeasureSpec.EXACTLY; if (lp.width != LayoutParams.FILL_PARENT) { widthSize = lp.width; } } if (lp.height != LayoutParams.WRAP_CONTENT) { heightMode = MeasureSpec.EXACTLY; if (lp.height != LayoutParams.FILL_PARENT) { heightSize = lp.height; } } final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode); final int heightSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode); child.measure(widthSpec, heightSpec); if (consumeVertical) { childHeightSize -= child.getMeasuredHeight(); } else if (consumeHorizontal) { childWidthSize -= child.getMeasuredWidth(); } } } } mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY); mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY); // Make sure we have created all fragments that we need to have shown. mInLayout = true; populate(); mInLayout = false; // Page views next. size = getChildCount(); for (int i = 0; i < size; ++i) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { if (DEBUG) Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (lp == null || !lp.isDecor) { final int widthSpec = MeasureSpec.makeMeasureSpec((int) (childWidthSize * lp.widthFactor), MeasureSpec.EXACTLY); child.measure(widthSpec, mChildHeightMeasureSpec); } } } }
From source file:android.support.design.widget.CoordinatorLayout.java
/** * Return the given gravity value or the default if the passed value is NO_GRAVITY. * This should be used for children that are positioned relative to a keyline. *//*from w w w.j a v a 2 s. c o m*/ private static int resolveKeylineGravity(int gravity) { return gravity == Gravity.NO_GRAVITY ? GravityCompat.END | Gravity.TOP : gravity; }
From source file:administrator.example.com.myscrollview.VerticalViewPager.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;/*from w w w .j a v a2 s.c o m*/ populate(); mInLayout = false; final int count = getChildCount(); int width = r - l; int height = b - t; int paddingLeft = getPaddingLeft(); int paddingTop = getPaddingTop(); int paddingRight = getPaddingRight(); int paddingBottom = getPaddingBottom(); final int scrollY = getScrollY(); int decorCount = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); ItemInfo ii; int childLeft = 0; int childTop = 0; if (lp.isDecor) { //XXX isDecorfalse final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (hgrav) { default: childLeft = paddingLeft; break; case Gravity.LEFT: childLeft = paddingLeft; paddingLeft += child.getMeasuredWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft); break; case Gravity.RIGHT: childLeft = width - paddingRight - child.getMeasuredWidth(); paddingRight += child.getMeasuredWidth(); break; } /* end of switch */ switch (vgrav) { default: childTop = paddingTop; break; case Gravity.TOP: childTop = paddingTop; paddingTop += child.getMeasuredHeight(); break; case Gravity.CENTER_VERTICAL: childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop); break; case Gravity.BOTTOM: childTop = height - paddingBottom - child.getMeasuredHeight(); paddingBottom += child.getMeasuredHeight(); break; } /* end of switch */ //XXX y? childTop += scrollY; decorCount++; child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight()); } else if ((ii = infoForChild(child)) != null) { //XXX ViewPager?? int toff = (height + mPageMargin) * ii.position; childLeft = paddingLeft; childTop = paddingTop + toff; if (DEBUG) Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + "," + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight()); child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight()); } /* end of if */ } /* end of if */ } /* end of for */ //XXX ? mLeftPageBounds = paddingLeft; mRightPageBounds = width - paddingRight; mDecorChildCount = decorCount; mFirstLayout = false; }