Example usage for android.view View setLayoutParams

List of usage examples for android.view View setLayoutParams

Introduction

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

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.appunite.list.HorizontalListView.java

private void measureScrapChild(View child, int position, int heightMeasureSpec) {
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (LayoutParams) generateDefaultLayoutParams();
        child.setLayoutParams(p);
    }/*from w  w  w . jav a 2s .  com*/
    p.viewType = mAdapter.getItemViewType(position);
    p.forceAdd = true;

    int childHeightSpec = ViewGroup.getChildMeasureSpec(heightMeasureSpec,
            mListPadding.top + mListPadding.bottom, p.height);
    int lpWidth = p.width;
    int childWidthSpec;
    if (lpWidth > 0) {
        childWidthSpec = MeasureSpec.makeMeasureSpec(lpWidth, MeasureSpec.EXACTLY);
    } else {
        childWidthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }
    child.measure(childWidthSpec, childHeightSpec);
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

private void measureScrapChildWidth(View child, int position, int heightMeasureSpec) {
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (AbsHListView.LayoutParams) generateDefaultLayoutParams();
        child.setLayoutParams(p);
    }//from w  w w  .  j a  v a2  s .  c  o m
    p.viewType = mAdapter.getItemViewType(position);
    p.forceAdd = true;

    int childHeightSpec = ViewGroup.getChildMeasureSpec(heightMeasureSpec,
            mListPadding.top + mListPadding.bottom, p.height);
    int lpWidth = p.width;
    int childWidthSpec;
    if (lpWidth > 0) {
        childWidthSpec = MeasureSpec.makeMeasureSpec(lpWidth, MeasureSpec.EXACTLY);
    } else {
        childWidthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }
    child.measure(childWidthSpec, childHeightSpec);
}

From source file:com.awrtechnologies.valor.valorfireplace.hlistview.widget.HListView.java

private void measureScrapChildWidth(View child, int position, int heightMeasureSpec) {
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (AbsHListView.LayoutParams) generateDefaultLayoutParams();
        child.setLayoutParams(p);
    }/*from  ww w  .  j  av  a2  s.c o  m*/
    p.viewType = mAdapter.getItemViewType(position);
    p.forceAdd = true;

    int childHeightSpec = ViewGroup.getChildMeasureSpec(heightMeasureSpec,
            mListPadding.top + mListPadding.bottom, p.height);
    int lpWidth = p.width;
    int childWidthSpec;
    if (lpWidth > 0) {
        childWidthSpec = View.MeasureSpec.makeMeasureSpec(lpWidth, View.MeasureSpec.EXACTLY);
    } else {
        childWidthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    }
    child.measure(childWidthSpec, childHeightSpec);
}

From source file:com.appunite.list.ListView.java

private void measureScrapChild(View child, int position, int widthMeasureSpec) {
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (AbsListView.LayoutParams) generateDefaultLayoutParams();
        child.setLayoutParams(p);
    }//from w w  w.ja  v  a2  s .com
    p.viewType = mAdapter.getItemViewType(position);
    p.forceAdd = true;

    int childWidthSpec = ViewGroup.getChildMeasureSpec(widthMeasureSpec, mListPadding.left + mListPadding.right,
            p.width);
    int lpHeight = p.height;
    int childHeightSpec;
    if (lpHeight > 0) {
        childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
    } else {
        childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    }
    child.measure(childWidthSpec, childHeightSpec);
}

From source file:cn.iterlog.myapplication.widget.overscroll.StaggeredGridView.java

/**
 * Obtain a populated view from the adapter. If optScrap is non-null and is not
 * reused it will be placed in the recycle bin.
 *
 * @param position position to get view for
 * @param optScrap Optional scrap view; will be reused if possible
 * @return A new view, a recycled view from mRecycler, or optScrap
 *//*w w w . j av  a 2s. c  o m*/
final View obtainView(int position, View optScrap) {
    View view = mRecycler.getTransientStateView(position);
    if (view != null) {
        return view;
    }

    if (position >= mAdapter.getCount()) {
        view = null;
        return null;
    }

    // Reuse optScrap if it's of the right type (and not null)
    final int optType = optScrap != null ? ((LayoutParams) optScrap.getLayoutParams()).viewType : -1;
    final int positionViewType = mAdapter.getItemViewType(position);
    final View scrap = optType == positionViewType ? optScrap : mRecycler.getScrapView(positionViewType);

    view = mAdapter.getView(position, scrap, this);

    if (view != scrap && scrap != null) {
        // The adapter didn't use it; put it back.
        mRecycler.addScrap(scrap);
    }

    ViewGroup.LayoutParams lp = view.getLayoutParams();

    if (view.getParent() != this) {
        if (lp == null) {
            lp = generateDefaultLayoutParams();
        } else if (!checkLayoutParams(lp)) {
            lp = generateLayoutParams(lp);
        }
    }

    final LayoutParams sglp = (LayoutParams) lp;
    sglp.position = position;
    sglp.viewType = positionViewType;

    //Set the updated LayoutParam before returning the view.
    view.setLayoutParams(sglp);
    return view;
}

From source file:com.app.afteryou.ui.staggered.StaggeredGridView.java

/**
 * Obtain a populated view from the adapter. If optScrap is non-null and is
 * not reused it will be placed in the recycle bin.
 * //  ww  w . j av  a  2 s  .  c om
 * @param position
 *            position to get view for
 * @param optScrap
 *            Optional scrap view; will be reused if possible
 * @return A new view, a recycled view from mRecycler, or optScrap
 */
final View obtainView(int position, View optScrap) {
    View view = mRecycler.getTransientStateView(position);
    if (view != null) {
        return view;
    }

    if (position >= mAdapter.getCount()) {
        view = null;
        return null;
    }

    // Reuse optScrap if it's of the right type (and not null)
    final int optType = optScrap != null ? ((LayoutParams) optScrap.getLayoutParams()).viewType : -1;
    final int positionViewType = mAdapter.getItemViewType(position);
    final View scrap = optType == positionViewType ? optScrap : mRecycler.getScrapView(positionViewType);

    view = mAdapter.getView(position, scrap, this);

    if (view != scrap && scrap != null) {
        // The adapter didn't use it; put it back.
        mRecycler.addScrap(scrap);
    }

    ViewGroup.LayoutParams lp = view.getLayoutParams();

    if (view.getParent() != this) {
        if (lp == null) {
            lp = generateDefaultLayoutParams();
        } else if (!checkLayoutParams(lp)) {
            lp = generateLayoutParams(lp);
        }
    }

    final LayoutParams sglp = (LayoutParams) lp;
    sglp.position = position;
    sglp.viewType = positionViewType;
    view.setLayoutParams(sglp);

    return view;
}

From source file:com.ad.view.staggeredgridview.StaggeredGridView.java

/**
 * Obtain a populated view from the adapter. If optScrap is non-null and is
 * not reused it will be placed in the recycle bin.
 * //from  w ww  .jav  a 2 s. c o  m
 * @param position
 *            position to get view for
 * @param optScrap
 *            Optional scrap view; will be reused if possible
 * @return A new view, a recycled view from mRecycler, or optScrap
 */
final View obtainView(int position, View optScrap) {
    View view = mRecycler.getTransientStateView(position);
    if (view != null) {
        return view;
    }

    if (position >= mAdapter.getCount()) {
        view = null;
        return null;
    }

    // Reuse optScrap if it's of the right type (and not null)
    final int optType = optScrap != null ? ((LayoutParams) optScrap.getLayoutParams()).viewType : -1;
    final int positionViewType = mAdapter.getItemViewType(position);
    final View scrap = optType == positionViewType ? optScrap : mRecycler.getScrapView(positionViewType);

    view = mAdapter.getView(position, scrap, this);

    if (view != scrap && scrap != null) {
        // The adapter didn't use it; put it back.
        mRecycler.addScrap(scrap);
    }

    ViewGroup.LayoutParams lp = view.getLayoutParams();

    if (view.getParent() != this) {
        if (lp == null) {
            lp = generateDefaultLayoutParams();
        } else if (!checkLayoutParams(lp)) {
            lp = generateLayoutParams(lp);
        }
    }

    final LayoutParams sglp = (LayoutParams) lp;
    sglp.position = position;
    sglp.viewType = positionViewType;

    // Set the updated LayoutParam before returning the view.
    view.setLayoutParams(sglp);
    return view;
}

From source file:br.com.devmix.baseapp.listener.OnSwipeableRecyclerViewTouchListener.java

private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalLayoutParamsHeight = lp.height;
    final int originalHeight = dismissView.getHeight();

    ValueAnimatorCompat animatorCompat = AnimatorCompatHelper.emptyValueAnimator();
    animatorCompat.setDuration(mAnimationTime);
    animatorCompat.addListener(new AnimatorListenerCompat() {
        @Override/* w ww . j  av a 2s  .com*/
        public void onAnimationStart(ValueAnimatorCompat animation) {
        }

        @Override
        public void onAnimationEnd(ValueAnimatorCompat animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);

                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }

                if (mFinalDelta > 0) {
                    mSwipeListener.onDismissedBySwipeRight(mRecyclerView, dismissPositions);
                } else {
                    mSwipeListener.onDismissedBySwipeLeft(mRecyclerView, dismissPositions);
                }

                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;

                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    ViewCompat.setAlpha(pendingDismiss.view, mAlpha);
                    ViewCompat.setTranslationX(pendingDismiss.view, 0);

                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalLayoutParamsHeight;

                    pendingDismiss.view.setLayoutParams(lp);
                }

                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mRecyclerView.dispatchTouchEvent(cancelEvent);

                mPendingDismisses.clear();
                mAnimatingPosition = ListView.INVALID_POSITION;
            }
        }

        @Override
        public void onAnimationCancel(ValueAnimatorCompat animation) {
        }

        @Override
        public void onAnimationRepeat(ValueAnimatorCompat animation) {
        }
    });
    animatorCompat.addUpdateListener(new AnimatorUpdateListenerCompat() {
        @Override
        public void onAnimationUpdate(ValueAnimatorCompat animation) {
            float fraction = animation.getAnimatedFraction();
            lp.height = (int) (originalHeight * (1 - fraction));
            dismissView.setLayoutParams(lp);
        }
    });

    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animatorCompat.start();
}

From source file:com.android.backups.StaggeredGridViewByJaumo.java

/**
 * Obtain a populated view from the adapter. If optScrap is non-null and is
 * not reused it will be placed in the recycle bin.
 * //  w  ww  .ja  va2s .c  om
 * @param position
 *            position to get view for
 * @param optScrap
 *            Optional scrap view; will be reused if possible
 * @return A new view, a recycled view from mRecycler, or optScrap
 */
final View obtainView(int position, View optScrap) {
    View view = mRecycler.getTransientStateView(position);
    if (view != null) {
        return view;
    }

    if (position >= mAdapter.getCount()) {
        view = null;
        return null;
    }

    // Reuse optScrap if it's of the right type (and not null)
    final int optType = optScrap != null ? ((LayoutParams) optScrap.getLayoutParams()).viewType : -1;
    final int positionViewType = mAdapter.getItemViewType(position);
    final View scrap = optType == positionViewType ? optScrap : mRecycler.getScrapView(positionViewType);

    view = mAdapter.getView(position, scrap, this);

    if (view != scrap && scrap != null) {
        // The adapter didn't use it; put it back.
        mRecycler.addScrap(scrap);
    }

    ViewGroup.LayoutParams lp = view.getLayoutParams();

    if (view.getParent() != this) {
        if (lp == null) {
            lp = generateDefaultLayoutParams();
        } else if (!checkLayoutParams(lp)) {
            lp = generateLayoutParams(lp);
        }
        view.setLayoutParams(lp);
    }

    final LayoutParams sglp = (LayoutParams) lp;
    sglp.position = position;
    sglp.viewType = positionViewType;

    return view;
}

From source file:com.aimfire.demo.CamcorderActivity.java

private void adjustUIControls(int rotation) {
    RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mShutterLayout.getLayoutParams();
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
    layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    mShutterLayout.setLayoutParams(layoutParams);
    mShutterLayout.setRotation(rotation);

    layoutParams = (RelativeLayout.LayoutParams) mPvButton.getLayoutParams();
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
    layoutParams.addRule(RelativeLayout.ABOVE, 0);
    layoutParams.addRule(RelativeLayout.BELOW, R.id.shutter_layout);
    mPvButton.setLayoutParams(layoutParams);
    mPvButton.setRotation(rotation);//from   w w w . j  av  a  2s.  co m

    /*
    layoutParams = (RelativeLayout.LayoutParams)mFbButton.getLayoutParams();
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
    layoutParams.addRule(RelativeLayout.ABOVE, R.id.shutter_layout);
    layoutParams.addRule(RelativeLayout.BELOW, 0);
    mFbButton.setLayoutParams(layoutParams);
    mFbButton.setRotation(rotation);
    */

    layoutParams = (RelativeLayout.LayoutParams) mExitButton.getLayoutParams();
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
    mExitButton.setLayoutParams(layoutParams);
    mExitButton.setRotation(rotation);

    layoutParams = (RelativeLayout.LayoutParams) mView3DButton.getLayoutParams();
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    mView3DButton.setLayoutParams(layoutParams);
    mView3DButton.setRotation(rotation);

    View view3DPb = findViewById(R.id.view3D_progress_bar);
    layoutParams = (RelativeLayout.LayoutParams) view3DPb.getLayoutParams();
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    view3DPb.setLayoutParams(layoutParams);
    view3DPb.setRotation(rotation);

    layoutParams = (RelativeLayout.LayoutParams) mScanProgView.getLayoutParams();
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
    layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.LEFT_OF, 0);
    layoutParams.addRule(RelativeLayout.RIGHT_OF, 0);
    mScanProgView.setLayoutParams(layoutParams);
    mScanProgView.setRotation(rotation);

    layoutParams = (RelativeLayout.LayoutParams) mScanModeButton.getLayoutParams();
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
    layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.LEFT_OF, 0);
    layoutParams.addRule(RelativeLayout.RIGHT_OF, 0);
    mScanModeButton.setLayoutParams(layoutParams);
    mScanModeButton.setRotation(rotation);

    layoutParams = (RelativeLayout.LayoutParams) mLevelButton.getLayoutParams();
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
    mLevelButton.setLayoutParams(layoutParams);
    mLevelButton.setRotation(rotation);

    layoutParams = (RelativeLayout.LayoutParams) mTimeCounter.getLayoutParams();
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
    layoutParams.addRule(RelativeLayout.LEFT_OF, R.id.mode_button);
    layoutParams.addRule(RelativeLayout.RIGHT_OF, 0);
    layoutParams.addRule(RelativeLayout.ABOVE, 0);
    layoutParams.addRule(RelativeLayout.BELOW, 0);
    mTimeCounter.setLayoutParams(layoutParams);

    if ((rotation == 0) || (rotation == 180)) {
        mTimeCounter.setTranslationY(0);
    } else {
        mTimeCounter.setTranslationY(mTimeCounter.getWidth() / 2);
    }
    mTimeCounter.setRotation(rotation);

    CustomToast.setRotation(rotation);
}