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.aidy.bottomdrawerlayout.BottomDrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { Log.i(TAG, "drawChild()"); final int width = getWidth(); final boolean drawingContent = isContentView(child); int clipTop = 0; int clipBottom = getHeight(); final int restoreCount = canvas.save(); if (drawingContent) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View v = getChildAt(i); if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v) || v.getWidth() < width) { Log.i(TAG, "drawChild() -- 0"); continue; }/* w w w . j a v a 2 s .c o m*/ if (checkDrawerViewAbsoluteGravity(v, Gravity.TOP)) { final int vbottom = v.getBottom(); if (vbottom > clipTop) clipTop = vbottom; } else { final int vtop = v.getTop(); if (vtop < clipBottom) { clipBottom = vtop; } } } canvas.clipRect(0, clipTop, getWidth(), clipBottom); } final boolean result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(restoreCount); if (mScrimOpacity > 0 && drawingContent) { Log.i(TAG, "drawChild() -- drawingContent"); final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mScrimOpacity); final int color = imag << 24 | (mScrimColor & 0xffffff); mScrimPaint.setColor(color); canvas.drawRect(0, clipTop, getWidth(), clipBottom, mScrimPaint); } else if (mShadowBottom != null && checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) { Log.i(TAG, "drawChild() -- Gravity.BOTTOM"); final int shadowHeight = mShadowBottom.getIntrinsicWidth(); final int childTop = child.getTop(); final int showing = getHeight() - childTop; final int drawerPeekDistance = mBottomDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); mShadowBottom.setBounds(child.getLeft(), childTop - shadowHeight, child.getRight(), childTop); mShadowBottom.setAlpha((int) (0xff * alpha)); mShadowBottom.draw(canvas); } return result; }
From source file:android.support.v7.widget.SwitchCompat.java
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); int opticalInsetLeft = 0; int opticalInsetRight = 0; if (mThumbDrawable != null) { final Rect trackPadding = mTempRect; if (mTrackDrawable != null) { mTrackDrawable.getPadding(trackPadding); } else {/*from w ww . j a v a 2s .c o m*/ trackPadding.setEmpty(); } final Rect insets = DrawableUtils.getOpticalBounds(mThumbDrawable); opticalInsetLeft = Math.max(0, insets.left - trackPadding.left); opticalInsetRight = Math.max(0, insets.right - trackPadding.right); } final int switchRight; final int switchLeft; if (ViewUtils.isLayoutRtl(this)) { switchLeft = getPaddingLeft() + opticalInsetLeft; switchRight = switchLeft + mSwitchWidth - opticalInsetLeft - opticalInsetRight; } else { switchRight = getWidth() - getPaddingRight() - opticalInsetRight; switchLeft = switchRight - mSwitchWidth + opticalInsetLeft + opticalInsetRight; } final int switchTop; final int switchBottom; switch (getGravity() & Gravity.VERTICAL_GRAVITY_MASK) { default: case Gravity.TOP: switchTop = getPaddingTop(); switchBottom = switchTop + mSwitchHeight; break; case Gravity.CENTER_VERTICAL: switchTop = (getPaddingTop() + getHeight() - getPaddingBottom()) / 2 - mSwitchHeight / 2; switchBottom = switchTop + mSwitchHeight; break; case Gravity.BOTTOM: switchBottom = getHeight() - getPaddingBottom(); switchTop = switchBottom - mSwitchHeight; break; } mSwitchLeft = switchLeft; mSwitchTop = switchTop; mSwitchBottom = switchBottom; mSwitchRight = switchRight; }
From source file:com.aidy.bottomdrawerlayout.DrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { Log.i(TAG, "onLayout()"); mInLayout = true;// ww w.j a va 2 s . com final int width = r - l; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isContentView(child)) { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } else { // Drawer, if it wasn't onMeasure would have thrown an // exception. final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childLeft; final float newOffset; if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) { childLeft = -childWidth + (int) (childWidth * lp.onScreen); newOffset = (float) (childWidth + childLeft) / childWidth; } else { // Right; onMeasure checked for us. childLeft = width - (int) (childWidth * lp.onScreen); newOffset = (float) (width - childLeft) / childWidth; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin, childLeft + childWidth, lp.topMargin + childHeight); break; } case Gravity.BOTTOM: { final int height = b - t; child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin); break; } case Gravity.CENTER_VERTICAL: { final int height = b - t; int childTop = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin) { childTop = lp.topMargin; } else if (childTop + childHeight > height - lp.bottomMargin) { childTop = height - lp.bottomMargin - childHeight; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } if (changeOffset) { setDrawerViewOffset(child, newOffset); } final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE; if (child.getVisibility() != newVisibility) { child.setVisibility(newVisibility); } } } mInLayout = false; mFirstLayout = false; }
From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
@Override protected boolean drawChild(Canvas canvas, View child, long drawingTime) { final int width = getWidth(); final boolean drawingContent = isContentView(child); int clipTop = 0, clipBottom = getHeight(); final int restoreCount = canvas.save(); if (drawingContent) { final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View v = getChildAt(i); if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v) || v.getWidth() < width) { continue; }/*from w w w.ja va 2 s. com*/ if (checkDrawerViewGravity(v, Gravity.TOP)) { final int vbottom = v.getBottom(); if (vbottom > clipTop) clipTop = vbottom; } else { final int vtop = v.getTop(); if (vtop < clipBottom) clipBottom = vtop; } } canvas.clipRect(0, clipTop, getWidth(), clipBottom); } final boolean result = super.drawChild(canvas, child, drawingTime); canvas.restoreToCount(restoreCount); if (mScrimOpacity > 0 && drawingContent) { final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; final int imag = (int) (baseAlpha * mScrimOpacity); final int color = imag << 24 | (mScrimColor & 0xffffff); mScrimPaint.setColor(color); canvas.drawRect(0, clipTop, getWidth(), clipBottom, mScrimPaint); } else if (mShadowTop != null && checkDrawerViewGravity(child, Gravity.TOP)) { final int shadowHeight = mShadowTop.getIntrinsicHeight(); final int childBottom = child.getBottom(); final int drawerPeekDistance = mTopDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) childBottom / drawerPeekDistance, 1.f)); mShadowTop.setBounds(child.getLeft(), childBottom, child.getRight(), childBottom + shadowHeight); mShadowTop.setAlpha((int) (0xff * alpha)); mShadowTop.draw(canvas); } else if (mShadowBottom != null && checkDrawerViewGravity(child, Gravity.BOTTOM)) { final int shadowHeight = mShadowBottom.getIntrinsicHeight(); final int childTop = child.getTop(); final int showing = getHeight() - childTop; final int drawerPeekDistance = mBottomDragger.getEdgeSize(); final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f)); mShadowTop.setBounds(child.getLeft(), childTop - shadowHeight, child.getRight(), childTop); mShadowBottom.setAlpha((int) (0xff * alpha)); mShadowBottom.draw(canvas); } return result; }
From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java
@Override // NestedScrollingParent public void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) { boolean scrolledUp = dyConsumed < 0; boolean scrolledDown = dyConsumed > 0; boolean overScrolledUp = dyUnconsumed < 0; boolean overScrolledDown = dyUnconsumed > 0; // When the top drawer is open, we need to track whether it can be closed. if (mTopDrawerView != null && mTopDrawerView.isOpened()) { // When the top drawer is overscrolled down or cannot scroll down, we consider it to be // at the bottom of its content, so it can be closed. mCanTopDrawerBeClosed = overScrolledDown || !mTopDrawerView.getDrawerContent().canScrollVertically(DOWN); // If the last scroll was a fling and the drawer can be closed, pass along the last // touch event to start closing the drawer. See the javadocs on mLastScrollWasFling // for more information. if (mCanTopDrawerBeClosed && mLastScrollWasFling) { onTouchEvent(mDrawerOpenLastInterceptedTouchEvent); }//from ww w .ja v a 2 s. c om mLastScrollWasFling = false; return; } // When the bottom drawer is open, we need to track whether it can be closed. if (mBottomDrawerView != null && mBottomDrawerView.isOpened()) { // When the bottom drawer is scrolled to the top of its content, it can be closed. mCanBottomDrawerBeClosed = overScrolledUp; // If the last scroll was a fling and the drawer can be closed, pass along the last // touch event to start closing the drawer. See the javadocs on mLastScrollWasFling // for more information. if (mCanBottomDrawerBeClosed && mLastScrollWasFling) { onTouchEvent(mDrawerOpenLastInterceptedTouchEvent); } mLastScrollWasFling = false; return; } mLastScrollWasFling = false; // The following code assumes that neither drawer is open. // The bottom and top drawer are not open. Look at the scroll events to figure out whether // a drawer should peek, close it's peek, or do nothing. boolean canTopAutoPeek = mTopDrawerView != null && mTopDrawerView.isAutoPeekEnabled(); boolean canBottomAutoPeek = mBottomDrawerView != null && mBottomDrawerView.isAutoPeekEnabled(); boolean isTopDrawerPeeking = mTopDrawerView != null && mTopDrawerView.isPeeking(); boolean isBottomDrawerPeeking = mBottomDrawerView != null && mBottomDrawerView.isPeeking(); boolean scrolledDownPastSlop = false; boolean shouldPeekOnScrollDown = mBottomDrawerView != null && mBottomDrawerView.isPeekOnScrollDownEnabled(); if (scrolledDown) { mCurrentNestedScrollSlopTracker += dyConsumed; scrolledDownPastSlop = mCurrentNestedScrollSlopTracker > mNestedScrollSlopPx; } if (canTopAutoPeek) { if (overScrolledUp && !isTopDrawerPeeking) { peekDrawer(Gravity.TOP); } else if (scrolledDown && isTopDrawerPeeking && !isClosingPeek(mTopDrawerView)) { closeDrawer(Gravity.TOP); } } if (canBottomAutoPeek) { if ((overScrolledDown || overScrolledUp) && !isBottomDrawerPeeking) { peekDrawer(Gravity.BOTTOM); } else if (shouldPeekOnScrollDown && scrolledDownPastSlop && !isBottomDrawerPeeking) { peekDrawer(Gravity.BOTTOM); } else if ((scrolledUp || (!shouldPeekOnScrollDown && scrolledDown)) && isBottomDrawerPeeking && !isClosingPeek(mBottomDrawerView)) { closeDrawer(mBottomDrawerView); } } }
From source file:com.matthewlogan.reversedrawerlayout.library.ReverseDrawerLayout.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true;// w w w .jav a2s . c om final int width = r - l; mDrawerOverhangDecimalOffset = mDrawerOverhang / (float) width; final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { continue; } final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (isContentView(child)) { child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(), lp.topMargin + child.getMeasuredHeight()); } else { // Drawer, if it wasn't onMeasure would have thrown an exception. if (mFirstLayout) { openDrawer(child); } child.setClickable(true); final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); int childLeft; final float newOffset; if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) { childLeft = -childWidth + (int) (childWidth * lp.onScreen); newOffset = (float) (childWidth + childLeft) / childWidth; } else { // Right; onMeasure checked for us. childLeft = width - (int) (childWidth * lp.onScreen); newOffset = (float) (width - childLeft) / childWidth; } final boolean changeOffset = newOffset != lp.onScreen; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin, childLeft + childWidth, lp.topMargin + childHeight); break; } case Gravity.BOTTOM: { final int height = b - t; child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin); break; } case Gravity.CENTER_VERTICAL: { final int height = b - t; int childTop = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin) { childTop = lp.topMargin; } else if (childTop + childHeight > height - lp.bottomMargin) { childTop = height - lp.bottomMargin - childHeight; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } if (changeOffset) { setDrawerViewOffset(child, newOffset); } final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE; if (child.getVisibility() != newVisibility) { child.setVisibility(newVisibility); } } } mInLayout = false; mFirstLayout = false; }
From source file:android.widget.Gallery.java
/** * Figure out vertical placement based on mGravity * /* ww w. ja v a 2s.co m*/ * @param child Child to place * @return Where the top of the child should be */ private int calculateTop(View child, boolean duringLayout) { int myHeight = duringLayout ? getMeasuredHeight() : getHeight(); int childHeight = duringLayout ? child.getMeasuredHeight() : child.getHeight(); int childTop = 0; switch (mGravity) { case Gravity.TOP: childTop = mSpinnerPadding.top; break; case Gravity.CENTER_VERTICAL: int availableSpace = myHeight - mSpinnerPadding.bottom - mSpinnerPadding.top - childHeight; childTop = mSpinnerPadding.top + (availableSpace / 2); break; case Gravity.BOTTOM: childTop = myHeight - mSpinnerPadding.bottom - childHeight; break; } return childTop; }
From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java
@Override ActionMode startSupportActionModeFromWindow(ActionMode.Callback callback) { endOnGoingFadeAnimation();// w ww. ja va 2 s. c o m if (mActionMode != null) { mActionMode.finish(); } final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapperV7(callback); ActionMode mode = null; if (mAppCompatCallback != null && !isDestroyed()) { try { mode = mAppCompatCallback.onWindowStartingSupportActionMode(wrappedCallback); } catch (AbstractMethodError ame) { // Older apps might not implement this callback method. } } if (mode != null) { mActionMode = mode; } else { if (mActionModeView == null) { if (mIsFloating) { // Use the action bar theme. final TypedValue outValue = new TypedValue(); final Resources.Theme baseTheme = mContext.getTheme(); baseTheme.resolveAttribute(R.attr.actionBarTheme_ox, outValue, true); final Context actionBarContext; if (outValue.resourceId != 0) { final Resources.Theme actionBarTheme = mContext.getResources().newTheme(); actionBarTheme.setTo(baseTheme); actionBarTheme.applyStyle(outValue.resourceId, true); actionBarContext = new ContextThemeWrapper(mContext, 0); actionBarContext.getTheme().setTo(actionBarTheme); } else { actionBarContext = mContext; } mActionModeView = new ActionBarContextView(actionBarContext); mActionModePopup = new PopupWindow(actionBarContext, null, R.attr.actionModePopupWindowStyle_ox); PopupWindowCompat.setWindowLayoutType(mActionModePopup, WindowManager.LayoutParams.TYPE_APPLICATION); mActionModePopup.setContentView(mActionModeView); mActionModePopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); actionBarContext.getTheme().resolveAttribute(R.attr.actionBarSize_ox, outValue, true); final int height = TypedValue.complexToDimensionPixelSize(outValue.data, actionBarContext.getResources().getDisplayMetrics()); mActionModeView.setContentHeight(height); mActionModePopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); mShowActionModePopup = new Runnable() { public void run() { mActionModePopup.showAtLocation(mActionModeView, Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0); endOnGoingFadeAnimation(); ViewCompat.setAlpha(mActionModeView, 0f); mFadeAnim = ViewCompat.animate(mActionModeView).alpha(1f); mFadeAnim.setListener(new ViewPropertyAnimatorListenerAdapter() { @Override public void onAnimationEnd(View view) { ViewCompat.setAlpha(mActionModeView, 1f); mFadeAnim.setListener(null); mFadeAnim = null; } @Override public void onAnimationStart(View view) { mActionModeView.setVisibility(View.VISIBLE); } }); } }; } else { ViewStubCompat stub = (ViewStubCompat) mSubDecor.findViewById(R.id.action_mode_bar_stub); if (stub != null) { // Set the layout inflater so that it is inflated with the action bar's context stub.setLayoutInflater(LayoutInflater.from(getActionBarThemedContext())); mActionModeView = (ActionBarContextView) stub.inflate(); } } } if (mActionModeView != null) { endOnGoingFadeAnimation(); mActionModeView.killMode(); mode = new StandaloneActionMode(mActionModeView.getContext(), mActionModeView, wrappedCallback, mActionModePopup == null); if (callback.onCreateActionMode(mode, mode.getMenu())) { mode.invalidate(); mActionModeView.initForMode(mode); mActionMode = mode; ViewCompat.setAlpha(mActionModeView, 0f); mFadeAnim = ViewCompat.animate(mActionModeView).alpha(1f); mFadeAnim.setListener(new ViewPropertyAnimatorListenerAdapter() { @Override public void onAnimationEnd(View view) { ViewCompat.setAlpha(mActionModeView, 1f); mFadeAnim.setListener(null); mFadeAnim = null; } @Override public void onAnimationStart(View view) { mActionModeView.setVisibility(View.VISIBLE); mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); if (mActionModeView.getParent() != null) { ViewCompat.requestApplyInsets((View) mActionModeView.getParent()); } } }); if (mActionModePopup != null) { mWindow.getDecorView().post(mShowActionModePopup); } } else { mActionMode = null; } } } if (mActionMode != null && mAppCompatCallback != null) { mAppCompatCallback.onSupportActionModeStarted(mActionMode); } return mActionMode; }
From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java
boolean isDrawerView(View child) { final int gravity = ((LayoutParams) child.getLayoutParams()).gravity; final int absGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(child)); return (absGravity & (Gravity.BOTTOM | Gravity.TOP)) != 0; }
From source file:com.androidhuman.circlerefreshlayout.SwipeRefreshLayout.java
@Override public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { // If we are in the middle of consuming, a scroll, then we want to move the spinner back up // before allowing the list to scroll if (Gravity.TOP == mPullPosition && dy > 0 && mTotalUnconsumed > 0) { if (dy > mTotalUnconsumed) { consumed[1] = dy - (int) mTotalUnconsumed; mTotalUnconsumed = 0;//from w w w. j a v a 2 s . com } else { mTotalUnconsumed -= dy; consumed[1] = dy; } moveSpinner(mTotalUnconsumed); } else if (Gravity.BOTTOM == mPullPosition && dy < 0 && mTotalUnconsumed < 0) { Log.e("Foo", "onNested-bottom"); } // If a client layout is using a custom start position for the circle // view, they mean to hide it again before scrolling the child view // If we get back to mTotalUnconsumed == 0 and there is more to go, hide // the circle so it isn't exposed if its blocking content is moved if (mUsingCustomStart && dy > 0 && mTotalUnconsumed == 0 && Math.abs(dy - consumed[1]) > 0) { mCircleView.setVisibility(View.GONE); } // Now let our nested parent consume the leftovers final int[] parentConsumed = mParentScrollConsumed; if (dispatchNestedPreScroll(dx - consumed[0], dy - consumed[1], parentConsumed, null)) { consumed[0] += parentConsumed[0]; consumed[1] += parentConsumed[1]; } }