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:com.actionbarsherlock.internal.widget.IcsLinearLayout.java

void drawDividersHorizontal(Canvas canvas) {
    final int count = getChildCount();
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);

        if (child != null && child.getVisibility() != GONE) {
            if (hasDividerBeforeChildAt(i)) {
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
                final int left = child.getLeft() - lp.leftMargin/* - mDividerWidth*/;
                drawVerticalDivider(canvas, left);
            }//from  w  w w .  j a va2 s  .c  o  m
        }
    }

    if (hasDividerBeforeChildAt(count)) {
        final View child = getChildAt(count - 1);
        int right = 0;
        if (child == null) {
            right = getWidth() - getPaddingRight() - mDividerWidth;
        } else {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            right = child.getRight()/* + lp.rightMargin*/;
        }
        drawVerticalDivider(canvas, right);
    }
}

From source file:carbon.internal.PercentLayoutHelper.java

/**
 * Iterates over children and changes their width and height to one calculated from percentage
 * values.//from ww  w .  j  a  v a2s. co m
 *
 * @param widthMeasureSpec  Width MeasureSpec of the parent ViewGroup.
 * @param heightMeasureSpec Height MeasureSpec of the parent ViewGroup.
 */
public void adjustChildren(int widthMeasureSpec, int heightMeasureSpec) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG,
                "adjustChildren: " + mHost + " widthMeasureSpec: " + View.MeasureSpec.toString(widthMeasureSpec)
                        + " heightMeasureSpec: " + View.MeasureSpec.toString(heightMeasureSpec));
    }

    int widthHint = View.MeasureSpec.getSize(widthMeasureSpec);
    int heightHint = View.MeasureSpec.getSize(heightMeasureSpec);
    for (int i = 0, N = mHost.getChildCount(); i < N; i++) {
        View view = mHost.getChildAt(i);
        ViewGroup.LayoutParams params = view.getLayoutParams();
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "should adjust " + view + " " + params);
        }
        if (params instanceof PercentLayoutParams) {
            PercentLayoutInfo info = ((PercentLayoutParams) params).getPercentLayoutInfo();
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "using " + info);
            }
            if (info != null) {
                if (params instanceof ViewGroup.MarginLayoutParams) {
                    info.fillMarginLayoutParams((ViewGroup.MarginLayoutParams) params, widthHint, heightHint);
                } else {
                    info.fillLayoutParams(params, widthHint, heightHint);
                }
            }
        }
    }
}

From source file:android.support.wear.widget.CircularProgressLayout.java

public CircularProgressLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mProgressDrawable = new CircularProgressDrawable(context);
    mProgressDrawable.setProgressRotation(DEFAULT_ROTATION);
    mProgressDrawable.setStrokeCap(Paint.Cap.BUTT);
    setBackground(mProgressDrawable);/* w  ww.jav a2s  . c  om*/

    // If a child view is added, make it center aligned so it fits in the progress drawable.
    setOnHierarchyChangeListener(new OnHierarchyChangeListener() {
        @Override
        public void onChildViewAdded(View parent, View child) {
            // Ensure that child view is aligned in center
            LayoutParams params = (LayoutParams) child.getLayoutParams();
            params.gravity = Gravity.CENTER;
            child.setLayoutParams(params);
        }

        @Override
        public void onChildViewRemoved(View parent, View child) {

        }
    });

    mController = new CircularProgressLayoutController(this);

    Resources r = context.getResources();
    TypedArray a = r.obtainAttributes(attrs, R.styleable.CircularProgressLayout);

    if (a.getType(R.styleable.CircularProgressLayout_colorSchemeColors) == TypedValue.TYPE_REFERENCE
            || !a.hasValue(R.styleable.CircularProgressLayout_colorSchemeColors)) {
        int arrayResId = a.getResourceId(R.styleable.CircularProgressLayout_colorSchemeColors,
                R.array.circular_progress_layout_color_scheme_colors);
        setColorSchemeColors(getColorListFromResources(r, arrayResId));
    } else {
        setColorSchemeColors(a.getColor(R.styleable.CircularProgressLayout_colorSchemeColors, Color.BLACK));
    }

    setStrokeWidth(a.getDimensionPixelSize(R.styleable.CircularProgressLayout_strokeWidth,
            r.getDimensionPixelSize(R.dimen.circular_progress_layout_stroke_width)));

    setBackgroundColor(a.getColor(R.styleable.CircularProgressLayout_backgroundColor,
            ContextCompat.getColor(context, R.color.circular_progress_layout_background_color)));

    setIndeterminate(a.getBoolean(R.styleable.CircularProgressLayout_indeterminate, false));

    a.recycle();
}

From source file:jp.co.ipublishing.esnavi.activities.MapActivity.java

/**
 * ????????/* w  w w .java 2s.  c om*/
 *
 * @param alert 
 */
private void updateLayout(@Nullable final Alert alert) {
    // ??

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            final View legendView = mLegendFragment.getView();
            final View mapView = mMapFragment.getView();

            if (legendView != null && mapView != null) {
                final LinearLayout.LayoutParams legendParams = (LinearLayout.LayoutParams) legendView
                        .getLayoutParams();
                final LinearLayout.LayoutParams mapParams = (LinearLayout.LayoutParams) mapView
                        .getLayoutParams();

                // FIXME: activity_map.xml?layout_weight???????????
                if (alert != null && alert.isEvacuationSituation()) {
                    // ???????
                    legendParams.weight = 3.0f;
                    mapParams.weight = 19.0f;
                } else {
                    // ????????
                    legendParams.weight = 0.0f;
                    mapParams.weight = 22.0f;
                }

                legendView.setLayoutParams(legendParams);
                mapView.setLayoutParams(mapParams);
            } else {
                // ?????????????????
                if (legendView == null) {
                    Log.w(TAG, "legendView is null...");
                }
                if (mapView == null) {
                    Log.w(TAG, "mapView is null...");
                }
            }
        }
    });
}

From source file:android.support.v17.leanback.widget.HorizontalHoverCardSwitcher.java

@Override
protected void onViewSelected(View view) {
    int rightLimit = getParentViewGroup().getWidth() - getParentViewGroup().getPaddingRight();
    int leftLimit = getParentViewGroup().getPaddingLeft();
    // measure the hover card width; if it's too large, align hover card
    // end edge with row view's end edge, otherwise align start edges.
    view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams();
    boolean isRtl = ViewCompat.getLayoutDirection(view) == View.LAYOUT_DIRECTION_RTL;
    if (!isRtl && mCardLeft + view.getMeasuredWidth() > rightLimit) {
        params.leftMargin = rightLimit - view.getMeasuredWidth();
    } else if (isRtl && mCardLeft < leftLimit) {
        params.leftMargin = leftLimit;//from  w  w  w .ja  va2 s  .  c o  m
    } else if (isRtl) {
        params.leftMargin = mCardRight - view.getMeasuredWidth();
    } else {
        params.leftMargin = mCardLeft;
    }
    view.requestLayout();
}

From source file:catchla.yep.adapter.decorator.DividerItemDecoration.java

public void drawVertical(Canvas c, RecyclerView parent) {
    if (mDivider == null)
        return;//  w  w  w. j  a  v a 2  s  . co  m
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final int childPos = parent.getChildAdapterPosition(child);
        final int start = getDecorationStart(), end = getDecorationEnd(parent);
        if (start >= 0 && childPos < start || end >= 0 && childPos > end)
            continue;
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin + Math.round(ViewCompat.getTranslationY(child));
        final int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left + mPadding.left, top + mPadding.top, right - mPadding.right,
                bottom - mPadding.bottom);
        mDivider.draw(c);
    }
}

From source file:catchla.yep.adapter.decorator.DividerItemDecoration.java

public void drawHorizontal(Canvas c, RecyclerView parent) {
    if (mDivider == null)
        return;/*from  w  w  w. j  a  va2s  .  c o  m*/
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final int childPos = parent.getChildAdapterPosition(child);
        final int start = getDecorationStart(), end = getDecorationEnd(parent);
        if (start >= 0 && childPos < start || end >= 0 && childPos > end)
            continue;
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int left = child.getRight() + params.rightMargin + Math.round(ViewCompat.getTranslationX(child));
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left + mPadding.left, top + mPadding.top, right - mPadding.right,
                bottom - mPadding.bottom);
        mDivider.draw(c);
    }
}

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

/**
 * Set the peek content view.//from ww w  . j  a  v  a2s . co m
 *
 * @param content The view to show when the drawer peeks.
 */
public void setPeekContent(View content) {
    ViewGroup.LayoutParams layoutParams = content.getLayoutParams();
    setPeekContent(content, -1 /* index */,
            layoutParams != null ? layoutParams : generateDefaultLayoutParams());
}

From source file:com.actionbarsherlock.internal.widget.IcsLinearLayout.java

@Override
protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed,
        int parentHeightMeasureSpec, int heightUsed) {
    final int index = indexOfChild(child);
    final int orientation = getOrientation();
    final LayoutParams params = (LayoutParams) child.getLayoutParams();
    if (hasDividerBeforeChildAt(index)) {
        if (orientation == VERTICAL) {
            //Account for the divider by pushing everything up
            params.topMargin = mDividerHeight;
        } else {/*from   w  w  w .ja  va 2 s.c o m*/
            //Account for the divider by pushing everything left
            params.leftMargin = mDividerWidth;
        }
    }

    final int count = getChildCount();
    if (index == count - 1) {
        if (hasDividerBeforeChildAt(count)) {
            if (orientation == VERTICAL) {
                params.bottomMargin = mDividerHeight;
            } else {
                params.rightMargin = mDividerWidth;
            }
        }
    }
    super.measureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec,
            heightUsed);
}

From source file:android.support.percent.PercentLayoutHelper.java

/**
 * Iterates over children and restores their original dimensions that were changed for
 * percentage values. Calling this method only makes sense if you previously called
 * {@link PercentLayoutHelper#adjustChildren(int, int)}.
 *//*w w w  .j  a  v a 2s.  c om*/
public void restoreOriginalParams() {
    for (int i = 0, N = mHost.getChildCount(); i < N; i++) {
        View view = mHost.getChildAt(i);
        ViewGroup.LayoutParams params = view.getLayoutParams();
        if (DEBUG) {
            Log.d(TAG, "should restore " + view + " " + params);
        }
        if (params instanceof PercentLayoutParams) {
            PercentLayoutInfo info = ((PercentLayoutParams) params).getPercentLayoutInfo();
            if (DEBUG) {
                Log.d(TAG, "using " + info);
            }
            if (info != null) {
                if (params instanceof ViewGroup.MarginLayoutParams) {
                    info.restoreMarginLayoutParams((ViewGroup.MarginLayoutParams) params);
                } else {
                    info.restoreLayoutParams(params);
                }
            }
        }
    }
}