Java Code Examples for android.view.View.setLayoutParams()

The following are Jave code examples for showing how to use setLayoutParams() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: TitleBarView   File: ViewUtil.java   View Source Code Vote up 6 votes
/**
 * 设置View的Margin
 *
 * @param view
 * @param left
 * @param top
 * @param right
 * @param bottom
 * @param width
 * @param height
 */
public void setViewMargin(View view, int left, int top, int right, int bottom, int width, int height) {
    if (view == null) {
        return;
    }
    ViewParent parent = view.getParent();
    if (parent == null) {
        return;
    }
    ViewGroup.MarginLayoutParams lp;
    if (parent instanceof LinearLayout) {
        lp = new LinearLayout.LayoutParams(width, height);
    } else if (parent instanceof RelativeLayout) {
        lp = new RelativeLayout.LayoutParams(width, height);
    } else if (parent instanceof FrameLayout) {
        lp = new FrameLayout.LayoutParams(width, height);
    } else {
        lp = new TableLayout.LayoutParams(width, height);
    }
    if (lp != null) {
        lp.setMargins(left, top, right, bottom);
        view.setLayoutParams(lp);
    }
}
 
Example 2
Project: boohee_v5.6   File: PureVideoView.java   View Source Code Vote up 6 votes
public void setRenderView(IRenderView renderView) {
    if (this.mRenderView != null) {
        if (this.mMediaPlayer != null) {
            this.mMediaPlayer.setDisplay(null);
        }
        View renderUIView = this.mRenderView.getView();
        this.mRenderView.removeRenderCallback(this.mSHCallback);
        this.mRenderView = null;
        removeView(renderUIView);
    }
    if (renderView != null) {
        this.mRenderView = renderView;
        renderView.setAspectRatio(this.mCurrentAspectRatio);
        if (this.mVideoWidth > 0 && this.mVideoHeight > 0) {
            renderView.setVideoSize(this.mVideoWidth, this.mVideoHeight);
        }
        if (this.mVideoSarNum > 0 && this.mVideoSarDen > 0) {
            renderView.setVideoSampleAspectRatio(this.mVideoSarNum, this.mVideoSarDen);
        }
        renderUIView = this.mRenderView.getView();
        renderUIView.setLayoutParams(new LayoutParams(-2, -2, 17));
        addView(renderUIView);
        this.mRenderView.addRenderCallback(this.mSHCallback);
        this.mRenderView.setVideoRotation(this.mVideoRotationDegree);
    }
}
 
Example 3
Project: AssistantBySDK   File: ActivityTitleBar.java   View Source Code Vote up 5 votes
private void initView(Context context) {
    View.inflate(context, R.layout.bar_activity_title, this);
    mTvTitle = (TextView) findViewById(R.id.tv_title);
    View statusBar = findViewById(R.id.status_bar);
    final GoBackActivity act = (GoBackActivity) context;
    ViewGroup.LayoutParams layoutParams = statusBar.getLayoutParams();
    layoutParams.height = ScreenUtil.getStatusBarHeight(act);
    statusBar.setLayoutParams(layoutParams);
    findViewById(R.id.tv_back).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            act.onBackPressed();
        }
    });
}
 
Example 4
Project: JazzyViewPager   File: JazzyViewPager.java   View Source Code Vote up 5 votes
private View wrapChild(View child) {
	if (!mOutlineEnabled || child instanceof OutlineContainer) return child;
	OutlineContainer out = new OutlineContainer(getContext());
	out.setLayoutParams(generateDefaultLayoutParams());
	child.setLayoutParams(new OutlineContainer.LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
	out.addView(child);
	return out;
}
 
Example 5
Project: redpacketui-open   File: HeaderViewCache.java   View Source Code Vote up 5 votes
@Override
public View getHeader(RecyclerView parent, int position) {
    long headerId = mAdapter.getHeaderId(position);

    View header = mHeaderViews.get(headerId);
    if (header == null) {
        //TODO - recycle views
        RecyclerView.ViewHolder viewHolder = mAdapter.onCreateHeaderViewHolder(parent);
        mAdapter.onBindHeaderViewHolder(viewHolder, position);
        header = viewHolder.itemView;
        if (header.getLayoutParams() == null) {
            header.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }

        int widthSpec;
        int heightSpec;

        if (mOrientationProvider.getOrientation(parent) == LinearLayoutManager.VERTICAL) {
            widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY);
            heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED);
        } else {
            widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.UNSPECIFIED);
            heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.EXACTLY);
        }

        int childWidth = ViewGroup.getChildMeasureSpec(widthSpec,
                parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width);
        int childHeight = ViewGroup.getChildMeasureSpec(heightSpec,
                parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height);
        header.measure(childWidth, childHeight);
        header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
        mHeaderViews.put(headerId, header);
    }
    return header;
}
 
Example 6
Project: QMUI_Android   File: SwipeBackLayout.java   View Source Code Vote up 5 votes
public static SwipeBackLayout wrap(View child, int edgeFlag) {
    SwipeBackLayout wrapper = new SwipeBackLayout(child.getContext());
    wrapper.setEdgeTrackingEnabled(edgeFlag);
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    child.setLayoutParams(lp);
    wrapper.addView(child);
    wrapper.setContentView(child);
    return wrapper;
}
 
Example 7
Project: FilterBar   File: GridContainer.java   View Source Code Vote up 5 votes
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom,
                           int oldLeft, int oldTop, int oldRight, int oldBottom) {
    if (right - left == oldRight - oldLeft) {
        return;
    }
    int cellWidth = mGrid.getWidth() / columnCount;
    for (int i = 0; i < mGrid.getChildCount(); ++i) {
        View cell = mGrid.getChildAt(i);
        GridLayout.LayoutParams lp = (GridLayout.LayoutParams) cell.getLayoutParams();
        lp.width = cellWidth;
        cell.setLayoutParams(lp);
    }
}
 
Example 8
Project: DexFixDemo   File: UI.java   View Source Code Vote up 5 votes
public static void setView(View view, int width, int height) {
    ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
    layoutParams.height = height;
    layoutParams.width = width;
    view.setLayoutParams(layoutParams);
    if (view.getParent() != null) {
        view.getParent().requestLayout();
    }
}
 
Example 9
Project: GCSApp   File: RvDateAdapter.java   View Source Code Vote up 5 votes
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = layoutInflater.inflate(R.layout.item_rv_date, parent, false);
    RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams();
    layoutParams.width = PixelUtil.getWidth(context) / 4;
    view.setLayoutParams(layoutParams);

    MyViewHolder viewHolder = new MyViewHolder(view);
    return viewHolder;
}
 
Example 10
Project: RLibrary   File: ItemInfoLayout.java   View Source Code Vote up 5 votes
static void resize(View view, int size, int margin) {
    ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
    layoutParams.rightMargin = margin;
    layoutParams.width = size;
    layoutParams.height = size;
    view.setLayoutParams(layoutParams);
}
 
Example 11
Project: SmoothRefreshLayout   File: SmoothRefreshLayout.java   View Source Code Vote up 5 votes
protected void addFreshViewLayoutParams(View view) {
    ViewGroup.LayoutParams lp = view.getLayoutParams();
    if (lp == null) {
        lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
    }
}
 
Example 12
Project: PXLSRT   File: PreviewActivity.java   View Source Code Vote up 5 votes
private void initializeColorSeekBar(Palette palette) {
    int defaultColor = 0x000000;
    int[] colors = {
            palette.getDominantColor(defaultColor),
            palette.getVibrantColor(defaultColor),
            palette.getMutedColor(defaultColor)};

    int px = ivPreview.getHeight() - (int) TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics());
    sbColor = new ColorSeekBar(PreviewActivity.this);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.setMargins(0, px, 0, 0);
    sbColor.setLayoutParams(params);
    sbColor.setColorSeeds(colors);
    sbColor.setBackground(ContextCompat.getDrawable(PreviewActivity.this, R.drawable.transparent));
    sbColor.setOnColorChangeListener(new ColorSeekBar.OnColorChangeListener() {
        @Override
        public void onColorChangeListener(int colorBarPosition, int alphaBarPosition, int color) {
            presenter.setColor(color);
        }
    });

    px = ivPreview.getHeight() - (int) TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics());
    int h = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
    vSeekBarBacking = new View(PreviewActivity.this);
    params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, h);
    params.setMargins(0, px, 0, 0);
    vSeekBarBacking.setLayoutParams(params);
    GradientDrawable gradient = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colors);
    gradient.setCornerRadius(0f);
    vSeekBarBacking.setBackground(gradient);

    rlRoot.addView(vSeekBarBacking);
    rlRoot.addView(sbColor);
}
 
Example 13
Project: ReadMark   File: SystemBarTintManager.java   View Source Code Vote up 5 votes
private void setupStatusBarView(Context context, ViewGroup decorViewGroup) {
    mStatusBarTintView = new View(context);
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight());
    params.gravity = Gravity.TOP;
    if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) {
        params.rightMargin = mConfig.getNavigationBarWidth();
    }
    mStatusBarTintView.setLayoutParams(params);
    mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
    mStatusBarTintView.setVisibility(View.GONE);
    decorViewGroup.addView(mStatusBarTintView);
}
 
Example 14
Project: BlurPopupWindow   File: SharePopup.java   View Source Code Vote up 5 votes
@Override
protected View createContentView(ViewGroup parent) {
    View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_bottom_popup, parent, false);
    LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.BOTTOM;
    view.setLayoutParams(lp);
    view.setVisibility(INVISIBLE);
    return view;
}
 
Example 15
Project: ForeverLibrary   File: SystemBarTintManager.java   View Source Code Vote up 5 votes
private void setupStatusBarView(Context context, ViewGroup decorViewGroup) {
    mStatusBarTintView = new View(context);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight());
    params.gravity = Gravity.TOP;
    if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) {
        params.rightMargin = mConfig.getNavigationBarWidth();
    }
    mStatusBarTintView.setLayoutParams(params);
    mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
    mStatusBarTintView.setVisibility(View.GONE);
    decorViewGroup.addView(mStatusBarTintView);
}
 
Example 16
Project: TopNotification   File: TopNotification.java   View Source Code Vote up 5 votes
private void addMask() {

        mMaskView = new View(mContext);
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        mMaskView.setLayoutParams(layoutParams);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {

            mMaskView.setBackgroundColor(mContext.getResources().getColor(R.color.transparent_gray));
        } else {

            mMaskView.setBackgroundColor(
                    mContext.getResources().getColor(R.color.transparent_gray, null));
        }

        WindowManager windowManager = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
        WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams();

        windowParams.gravity = Gravity.TOP | Gravity.LEFT;
        windowParams.x = 0;
        windowParams.y = 0;
        windowParams.height = WindowManager.LayoutParams.MATCH_PARENT;
        windowParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        windowParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
        windowParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;

        windowParams.format = PixelFormat.TRANSLUCENT;
        windowParams.windowAnimations = 0;
        windowManager.addView(mMaskView, windowParams);
        mMaskView.setVisibility(View.VISIBLE);
    }
 
Example 17
Project: StatusView   File: StatusManager.java   View Source Code Vote up 4 votes
private void setMarginTop(View contentView, float toolbarHeight) {
    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) contentView.getLayoutParams();
    lp.setMargins(lp.leftMargin, (int) toolbarHeight + lp.topMargin, lp.rightMargin, lp.bottomMargin);
    contentView.setLayoutParams(lp);
}
 
Example 18
Project: GitHub   File: AbstractFullFillLayoutHelper.java   View Source Code Vote up 4 votes
protected int getAllChildren(View[] toFill,
                             RecyclerView.Recycler recycler, LayoutStateWrapper layoutState,
                             LayoutChunkResult result, LayoutManagerHelper helper) {

    final boolean layingOutInPrimaryDirection = layoutState.getItemDirection() == LayoutStateWrapper.ITEM_DIRECTION_TAIL;

    int count = 0;
    int firstPos = layingOutInPrimaryDirection ? getRange().getLower() : getRange().getUpper();
    final int curPos = layoutState.getCurrentPosition();

    if (layingOutInPrimaryDirection ? (curPos > firstPos) : (curPos > firstPos)) {
        // do ugly bug fix now
        Log.w(TAG, "Please handle strange order views carefully");
    }

    while (count < toFill.length) {
        if (isOutOfRange(layoutState.getCurrentPosition()))
            break;

        View view = nextView(recycler, layoutState, helper, result);
        if (view == null) {
            break;
        }

        toFill[count] = view;

        // normalize layout params
        LayoutParams layoutParams = view.getLayoutParams();
        if (layoutParams == null) {
            view.setLayoutParams(generateDefaultLayoutParams());
        } else if (!checkLayoutParams(layoutParams)) {
            view.setLayoutParams(generateLayoutParams(layoutParams));
        }

        count++;
    }

    if (count > 0 && !layingOutInPrimaryDirection) {
        // reverse array
        int s = 0, e = count - 1;
        while (s < e) {
            View temp = toFill[s];
            toFill[s] = toFill[e];
            toFill[e] = temp;
            s++;
            e--;
        }
    }

    return count;
}
 
Example 19
Project: Nird2   File: AuthorView.java   View Source Code Vote up 4 votes
private void setCenterVertical(View v, boolean center) {
	LayoutParams params = (LayoutParams) v.getLayoutParams();
	params.addRule(CENTER_VERTICAL, center ? RelativeLayout.TRUE : 0);
	v.setLayoutParams(params);
}
 
Example 20
Project: baselibrary-master   File: BaseFragment.java   View Source Code Vote up 2 votes
/**
 * 设置控件宽度
 *
 * @param v     控件
 * @param width 宽度,MATCH_PARENT = -1, WRAP_CONTENT = -2;
 */
public void setWidth(@NonNull View v, int width) {
    ViewGroup.LayoutParams lp = v.getLayoutParams();
    lp.width = width;
    v.setLayoutParams(lp);
}