Example usage for android.view View getLayoutParams

List of usage examples for android.view View getLayoutParams

Introduction

In this page you can find the example usage for android.view View getLayoutParams.

Prototype

@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_")
public ViewGroup.LayoutParams getLayoutParams() 

Source Link

Document

Get the LayoutParams associated with this view.

Usage

From source file:android.support.design.widget.CoordinatorLayout.java

@Override
public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes) {
    mNestedScrollingParentHelper.onNestedScrollAccepted(child, target, nestedScrollAxes);
    mNestedScrollingDirectChild = child;
    mNestedScrollingTarget = target;//from  w ww.  j  a  v  a2 s . c om

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View view = getChildAt(i);
        final LayoutParams lp = (LayoutParams) view.getLayoutParams();
        if (!lp.isNestedScrollAccepted()) {
            continue;
        }

        final Behavior viewBehavior = lp.getBehavior();
        if (viewBehavior != null) {
            viewBehavior.onNestedScrollAccepted(this, view, child, target, nestedScrollAxes);
        }
    }
}

From source file:android.support.design.widget.CoordinatorLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    if (lp.mBehavior != null) {
        final float scrimAlpha = lp.mBehavior.getScrimOpacity(this, child);
        if (scrimAlpha > 0f) {
            if (mScrimPaint == null) {
                mScrimPaint = new Paint();
            }//from  w w w .j av a  2s.c  o m
            mScrimPaint.setColor(lp.mBehavior.getScrimColor(this, child));
            mScrimPaint.setAlpha(MathUtils.constrain(Math.round(255 * scrimAlpha), 0, 255));

            final int saved = canvas.save();
            if (child.isOpaque()) {
                // If the child is opaque, there is no need to draw behind it so we'll inverse
                // clip the canvas
                canvas.clipRect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom(),
                        Region.Op.DIFFERENCE);
            }
            // Now draw the rectangle for the scrim
            canvas.drawRect(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
                    getHeight() - getPaddingBottom(), mScrimPaint);
            canvas.restoreToCount(saved);
        }
    }
    return super.drawChild(canvas, child, drawingTime);
}

From source file:au.com.glassechidna.velocityviewpager.VelocityViewPager.java

private void transformPages() {
    if (mPageTransformer != null) {
        final int scrollX = getScrollX();
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();

            if (lp.isDecor)
                continue;

            final float transformPos = (float) (child.getLeft() - scrollX) / getClientWidth();
            mPageTransformer.transformPage(child, transformPos);
        }// w  w  w.java2s  .co  m
    }
}

From source file:android.support.design.widget.CoordinatorLayout.java

/**
 * Reset all Behavior-related tracking records either to clean up or in preparation
 * for a new event stream. This should be called when attached or detached from a window,
 * in response to an UP or CANCEL event, when intercept is request-disallowed
 * and similar cases where an event stream in progress will be aborted.
 *///  w w  w .  j  a  v  a2  s.c o  m
private void resetTouchBehaviors() {
    if (mBehaviorTouchView != null) {
        final Behavior b = ((LayoutParams) mBehaviorTouchView.getLayoutParams()).getBehavior();
        if (b != null) {
            final long now = SystemClock.uptimeMillis();
            final MotionEvent cancelEvent = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0.0f, 0.0f,
                    0);
            b.onTouchEvent(this, mBehaviorTouchView, cancelEvent);
            cancelEvent.recycle();
        }
        mBehaviorTouchView = null;
    }

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        lp.resetTouchBehaviorTracking();
    }
    mDisallowInterceptReset = false;
}

From source file:android.support.design.widget.CoordinatorLayout.java

@Override
public void onStopNestedScroll(View target) {
    mNestedScrollingParentHelper.onStopNestedScroll(target);

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View view = getChildAt(i);
        final LayoutParams lp = (LayoutParams) view.getLayoutParams();
        if (!lp.isNestedScrollAccepted()) {
            continue;
        }//  w  ww .  j a va  2  s .co  m

        final Behavior viewBehavior = lp.getBehavior();
        if (viewBehavior != null) {
            viewBehavior.onStopNestedScroll(this, view, target);
        }
        lp.resetNestedScroll();
        lp.resetChangedAfterNestedScroll();
    }

    mNestedScrollingDirectChild = null;
    mNestedScrollingTarget = null;
}

From source file:android.support.design.widget.CoordinatorLayout.java

@Override
public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final Behavior behavior = lp.getBehavior();

    if (behavior != null && behavior.onRequestChildRectangleOnScreen(this, child, rectangle, immediate)) {
        return true;
    }//from w w  w  .j  a  v a 2  s .co m

    return super.requestChildRectangleOnScreen(child, rectangle, immediate);
}

From source file:android.support.design.widget.CoordinatorLayout.java

/**
 * Lay out a child view with no special handling. This will position the child as
 * if it were within a FrameLayout or similar simple frame.
 *
 * @param child child view to lay out/*w  ww .  j a v a  2  s .c  o m*/
 * @param layoutDirection ViewCompat constant for the desired layout direction
 */
private void layoutChild(View child, int layoutDirection) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final Rect parent = acquireTempRect();
    parent.set(getPaddingLeft() + lp.leftMargin, getPaddingTop() + lp.topMargin,
            getWidth() - getPaddingRight() - lp.rightMargin,
            getHeight() - getPaddingBottom() - lp.bottomMargin);

    if (mLastInsets != null && ViewCompat.getFitsSystemWindows(this)
            && !ViewCompat.getFitsSystemWindows(child)) {
        // If we're set to handle insets but this child isn't, then it has been measured as
        // if there are no insets. We need to lay it out to match.
        parent.left += mLastInsets.getSystemWindowInsetLeft();
        parent.top += mLastInsets.getSystemWindowInsetTop();
        parent.right -= mLastInsets.getSystemWindowInsetRight();
        parent.bottom -= mLastInsets.getSystemWindowInsetBottom();
    }

    final Rect out = acquireTempRect();
    GravityCompat.apply(resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), parent,
            out, layoutDirection);
    child.layout(out.left, out.top, out.right, out.bottom);

    releaseTempRect(parent);
    releaseTempRect(out);
}

From source file:au.com.glassechidna.velocityviewpager.VelocityViewPager.java

private void updateViewOnClickListeners() {
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams layoutParams = (LayoutParams) child.getLayoutParams();
        if (!layoutParams.isDecor) {
            if (mOnItemClickListener != null) {
                child.setOnClickListener(this);
            }/* w  w  w. j av  a 2  s  . c om*/
        }
    }
}

From source file:au.com.glassechidna.velocityviewpager.VelocityViewPager.java

private void updateViewOnLongClickListeners() {
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final LayoutParams layoutParams = (LayoutParams) child.getLayoutParams();
        if (!layoutParams.isDecor) {
            if (mOnItemLongClickListener != null) {
                child.setOnLongClickListener(this);
            }/* w ww  .  j  ava  2  s  .  co m*/
        }
    }
}

From source file:android.support.design.widget.CoordinatorLayout.java

/**
 * CORE ASSUMPTION: anchor has been laid out by the time this is called for a given child view.
 *
 * @param child child to lay out/*from   ww  w.j a v a2  s  . c o  m*/
 * @param anchor view to anchor child relative to; already laid out.
 * @param layoutDirection ViewCompat constant for layout direction
 */
private void layoutChildWithAnchor(View child, View anchor, int layoutDirection) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();

    final Rect anchorRect = acquireTempRect();
    final Rect childRect = acquireTempRect();
    try {
        getDescendantRect(anchor, anchorRect);
        getDesiredAnchoredChildRect(child, layoutDirection, anchorRect, childRect);
        child.layout(childRect.left, childRect.top, childRect.right, childRect.bottom);
    } finally {
        releaseTempRect(anchorRect);
        releaseTempRect(childRect);
    }
}