Example usage for android.view Gravity BOTTOM

List of usage examples for android.view Gravity BOTTOM

Introduction

In this page you can find the example usage for android.view Gravity BOTTOM.

Prototype

int BOTTOM

To view the source code for android.view Gravity BOTTOM.

Click Source Link

Document

Push object to the bottom of its container, not changing its size.

Usage

From source file:com.example.emachine.FXcalcActivity.java

private void ProgrammaticFAB() {
    if (getPrefBugIssue(getBaseContext()))
        Crashlytics.log(Log.ERROR, TAG, "ProgrammaticFAB ...");
    FloatingActionButton btn_pFAB = new FloatingActionButton.Builder(this)
            .withDrawable(getResources().getDrawable(R.drawable.idea)).withButtonColor(Color.BLUE)
            .withGravity(Gravity.BOTTOM | Gravity.LEFT).withMargins(0, 0, 16, 16).create();
    btn_pFAB.setOnClickListener(new View.OnClickListener() {

        @Override//from  w w  w .j  a v a2s  .com
        public void onClick(View v) {
            Snackbar.make(v, "Programmatic FAB selected.", Snackbar.LENGTH_LONG).setAction("Action", null)
                    .show();

        }
    });

}

From source file:com.doubleTwist.drawerlib.ADrawerLayout.java

private void readViews() {
    mContent = getChildAt(0);//w  ww. ja v  a  2s.  c om
    for (int i = 1, count = getChildCount(); i < count; i++) {
        View v = getChildAt(i);
        if (v.getId() == DIMMER_VIEW_ID)
            continue;
        LayoutParams params = (LayoutParams) v.getLayoutParams();
        switch (params.gravity) {
        case Gravity.LEFT: // left
            mLeft = v;
            mDrawerState.mLeftEnabled = true;
            break;
        case Gravity.RIGHT: // right
            mRight = v;
            mDrawerState.mRightEnabled = true;
            break;
        case Gravity.TOP: // top
            mTop = v;
            mDrawerState.mTopEnabled = true;
            break;
        case Gravity.BOTTOM: // bottom
            mBottom = v;
            mDrawerState.mBottomEnabled = true;
            break;
        default:
            mLeft = v;
            break;
        }
    }
}

From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java

/**
 * @param gravity the gravity of the child to return.
 * @return the drawer with the specified gravity
 *//*from ww w .ja  v a2 s . com*/
@Nullable
private WearableDrawerView findDrawerWithGravity(int gravity) {
    switch (gravity) {
    case Gravity.TOP:
        return mTopDrawerView;
    case Gravity.BOTTOM:
        return mBottomDrawerView;
    default:
        Log.w(TAG, "Invalid drawer gravity: " + gravity);
        return null;
    }
}

From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java

/**
 * 12-03 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() -- left = 0
 * -- top = 0 -- right = 1080 -- b = 1675 12-03 22:59:19.686:
 * I/BottomDrawerLayout(12480): onLayout() -- childWidth = 750 --
 * childHeight = 1675 -- lp.onScreen = 0.0 12-03 22:59:19.686:
 * I/BottomDrawerLayout(12480): onLayout() -- childLeft = -750 -- newOffset
 * = 0.0 12-03 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() --
 * childWidth = 750 -- childHeight = 1675 -- lp.onScreen = 0.0 12-03
 * 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() -- childLeft = 1080
 * -- newOffset = 0.0/*from   www  .j  a  v  a2  s . c o m*/
 */
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    Log.i(TAG, "onLayout() -- left = " + l + " -- top = " + t + " -- right = " + r + " -- b = " + b);
    mInLayout = true;
    final int width = r - l;// 
    final int height = b - t;// 
    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 {
            // ?view
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            // Log.i(TAG, "onLayout() -- childWidth = " + childWidth +
            // " -- childHeight = " + childHeight
            // + " -- lp.onScreen = " + lp.onScreen);
            int childLeft = 0;// 
            int childTop = 0;// 
            float newOffset = 0;// 

            switch (getDrawerViewAbsoluteGravity(child)) {
            case Gravity.LEFT:
                if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) {
                    // Log.i(TAG, "onLayout() -- 1");
                    childLeft = -childWidth + (int) (childWidth * lp.onScreen);
                    newOffset = (float) (childWidth + childLeft) / childWidth;// ?
                }
                break;
            case Gravity.RIGHT:
                if (checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) {
                    // Log.i(TAG, "onLayout() -- 2");
                    childLeft = width - (int) (childWidth * lp.onScreen);
                    newOffset = (float) (width - childLeft) / childWidth;// ?
                }
                break;
            case Gravity.TOP:
                if (checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) {
                    // Log.i(TAG, "onLayout() -- 3");
                    childTop = -childHeight + (int) (childHeight * lp.onScreen);
                    newOffset = (float) (childHeight + childTop) / childHeight;// ?
                }
                break;
            case Gravity.BOTTOM:
                if (checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) {
                    // Log.i(TAG, "onLayout() -- 4");
                    childTop = height - (int) (childHeight * lp.onScreen);
                    newOffset = (float) (height - childTop) / childHeight;// ?
                }
                break;
            default:
                childTop = height - (int) (childHeight * lp.onScreen);
                newOffset = (float) (height - childTop) / childHeight;// ?
                break;
            }
            // /////////////////////////////////////////
            // Log.i(TAG, "onLayout() -- childLeft = " + childLeft +
            // " -- newOffset = " + newOffset);
            final boolean changeOffset = newOffset != lp.onScreen;
            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
            switch (vgrav) {
            // case Gravity.TOP: {
            // Log.i(TAG, "onLayout() -- Gravity.TOP");
            // child.layout(childLeft, lp.topMargin, childLeft + childWidth,
            // lp.topMargin + childHeight);
            // break;
            // }
            // case Gravity.BOTTOM: {
            // Log.i(TAG, "onLayout() -- Gravity.BOTTOM");
            // child.layout(childLeft, height - lp.bottomMargin -
            // child.getMeasuredHeight(), childLeft
            // + childWidth, height - lp.bottomMargin);
            // break;
            // }
            case Gravity.CENTER_VERTICAL: {
                // Log.i(TAG, "onLayout() -- Gravity.CENTER_VERTICAL");
                int childTop_cv = (height - childHeight) / 2;

                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childTop_cv < lp.topMargin) {
                    childTop_cv = lp.topMargin;
                } else if (childTop_cv + childHeight > height - lp.bottomMargin) {
                    childTop_cv = height - lp.bottomMargin - childHeight;
                }
                child.layout(childLeft, childTop_cv, childLeft + childWidth, childTop_cv + 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.androidhuman.circlerefreshlayout.SwipeRefreshLayout.java

@Override
public void onNestedScroll(final View target, final int dxConsumed, final int dyConsumed,
        final int dxUnconsumed, final int dyUnconsumed) {
    // Dispatch up to the nested parent first
    dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, mParentOffsetInWindow);

    // This is a bit of a hack. Nested scrolling works from the bottom up, and as we are
    // sometimes between two nested scrolling views, we need a way to be able to know when any
    // nested scrolling parent has stopped handling events. We do that by using the
    // 'offset in window 'functionality to see if we have been moved from the event.
    // This is a decent indication of whether we should take over the event stream or not.
    final int dy = dyUnconsumed + mParentOffsetInWindow[1];
    if (Gravity.TOP == mPullPosition && dy < 0) {
        mTotalUnconsumed += Math.abs(dy);
        moveSpinner(mTotalUnconsumed);//from w  w w .  j  a  va 2s.c  o  m
    } else if (Gravity.BOTTOM == mPullPosition && dy > 0) {
        mTotalUnconsumed += Math.abs(dy);
        moveSpinner(mTotalUnconsumed);
    }
}

From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/*w ww  . j  a  va  2 s.  c  o m*/
    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.aidy.bottomdrawerlayout.BottomDrawerLayout.java

void closeDrawers(boolean peekingOnly) {
    boolean needsInvalidate = false;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (!isDrawerView(child) || (peekingOnly && !lp.isPeeking)) {
            continue;
        }//from   w  ww .  ja  va 2  s.co m
        if (checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) {
            needsInvalidate |= mBottomDragger.smoothSlideViewTo(child, child.getLeft(), getHeight());
        }
        lp.isPeeking = false;
    }
    mBottomCallback.removeCallbacks();

    if (needsInvalidate) {
        invalidate();
    }
}

From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final int height = getHeight();
    final boolean drawingContent = isContentView(child);
    int clipLeft = 0, clipRight = getWidth();

    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.getHeight() < height) {
                continue;
            }//w  ww.j a  v a2  s  . com

            if (checkDrawerViewAbsoluteGravity(v, Gravity.TOP)) {
                final int vright = v.getRight();
                if (vright > clipLeft)
                    clipLeft = vright;
            } else {
                final int vleft = v.getLeft();
                if (vleft < clipRight)
                    clipRight = vleft;
            }
        }
        canvas.clipRect(clipLeft, 0, clipRight, getHeight());
    }
    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(clipLeft, 0, clipRight, getHeight(), mScrimPaint);
    } else if (mShadowTop != null && checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) {
        final int shadowWidth = mShadowTop.getIntrinsicWidth();
        final int childRight = child.getRight();
        final int drawerPeekDistance = mTopDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f));
        mShadowTop.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom());
        mShadowTop.setAlpha((int) (0xff * alpha));
        mShadowTop.draw(canvas);
    } else if (mShadowBottom != null && checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) {
        final int shadowWidth = mShadowBottom.getIntrinsicWidth();
        final int childLeft = child.getLeft();
        final int showing = getWidth() - childLeft;
        final int drawerPeekDistance = mBottomDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowBottom.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom());
        mShadowBottom.setAlpha((int) (0xff * alpha));
        mShadowBottom.draw(canvas);
    }
    return result;
}

From source file:com.baidu.zhuanche.view.LazyViewPager.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));

    // Children are just made to fill our space.
    int childWidthSize = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
    int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();

    /*//from   ww  w.j a v a  2  s  .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;
                Log.d(TAG, "gravity: " + lp.gravity + " hgrav: " + hgrav + " vgrav: " + vgrav);
                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;
                }

                final int widthSpec = MeasureSpec.makeMeasureSpec(childWidthSize, widthMode);
                final int heightSpec = MeasureSpec.makeMeasureSpec(childHeightSize, 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) {
                child.measure(mChildWidthMeasureSpec, mChildHeightMeasureSpec);
            }
        }
    }
}