Java Code Examples for androidx.constraintlayout.widget.ConstraintLayout#LayoutParams

The following examples show how to use androidx.constraintlayout.widget.ConstraintLayout#LayoutParams . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamFragment.java    From Twire with GNU General Public License v3.0 6 votes vote down vote up
private void setVideoViewLayout() {
    ViewGroup.LayoutParams layoutParams = rootView.getLayoutParams();
    layoutParams.height = isLandscape ? ViewGroup.LayoutParams.MATCH_PARENT : ViewGroup.LayoutParams.WRAP_CONTENT;

    ConstraintLayout.LayoutParams layoutWrapper = (ConstraintLayout.LayoutParams) mVideoWrapper.getLayoutParams();
    if (isLandscape && !pictureInPictureEnabled) {
        layoutWrapper.width = mShowChatButton.getRotation() == 0 ? ConstraintLayout.LayoutParams.MATCH_PARENT : getScreenRect(getActivity()).height() - getLandscapeChatTargetWidth();
    } else {
        layoutWrapper.width = ConstraintLayout.LayoutParams.MATCH_PARENT;
    }
    mVideoWrapper.setLayoutParams(layoutWrapper);

    AspectRatioFrameLayout contentFrame = mVideoWrapper.findViewById(R.id.exo_content_frame);
    if (isLandscape) {
        contentFrame.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
    } else {
        contentFrame.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIXED_WIDTH);
    }
}
 
Example 2
Source File: LessonC.java    From SchoolQuest with GNU General Public License v3.0 6 votes vote down vote up
private void generatePoint() {
    int r = (int) (Math.random() * points.size());

    while (r == oldIndex) { r = (int) (Math.random() * points.size()); }

    int r0 = (int) (Math.random() * points.get(r).size());

    oldIndex = r;
    currentPoint = points.get(r).remove(r0);

    ImageView mapPoint = GameActivity.getInstance().findViewById(R.id.lesson_c_map_menu_point);

    ConstraintLayout.LayoutParams layoutParams =
            (ConstraintLayout.LayoutParams) mapPoint.getLayoutParams();
    layoutParams.topMargin =
            Math.round((currentPoint.y - PE_MAP_TOP_MARGIN) * 8 * SCREEN_DENSITY);
    layoutParams.leftMargin =
            Math.round((currentPoint.x - PE_MAP_LEFT_MARGIN) * 8 * SCREEN_DENSITY);
    mapPoint.setLayoutParams(layoutParams);
}
 
Example 3
Source File: ToolbarHelper.java    From CloudReader with Apache License 2.0 6 votes vote down vote up
/**
 * 将View的top margin 向下偏移一个状态栏的高度
 */
public static void initMarginTopDiffBar(View view) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (params instanceof LinearLayout.LayoutParams) {
        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) params;
        linearParams.topMargin += DensityUtil.getStatusHeight(view.getContext());
    } else if (params instanceof FrameLayout.LayoutParams) {
        FrameLayout.LayoutParams frameParams = (FrameLayout.LayoutParams) params;
        frameParams.topMargin += DensityUtil.getStatusHeight(view.getContext());
    } else if (params instanceof RelativeLayout.LayoutParams) {
        RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams) params;
        relativeParams.topMargin += DensityUtil.getStatusHeight(view.getContext());
    } else if (params instanceof ConstraintLayout.LayoutParams) {
        ConstraintLayout.LayoutParams constraintParams = (ConstraintLayout.LayoutParams) params;
        constraintParams.topMargin += DensityUtil.getStatusHeight(view.getContext());
    }
    view.setLayoutParams(params);
}
 
Example 4
Source File: WebViewDialog.java    From cloudflare-scrape-Android with MIT License 6 votes vote down vote up
private void initWebView(){
    mWebView = new WebView(mContext);
    ConstraintLayout.LayoutParams layoutParams =
            new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT);
    layoutParams.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
    layoutParams.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
    layoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
    layoutParams.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
    mWebView.setLayoutParams(layoutParams);
    mWebView.setId(R.id.webview);
    mWebView.setVisibility(View.INVISIBLE);
    mLayout.addView(mWebView,-1);
    mAdvanceWebClient = new AdvanceWebClient(getContext(), mWebView,mUser_agent);
    mAdvanceWebClient.setListener(mLoginSuccessListener);
    mAdvanceWebClient.initWebView("https://" + mUrl.getHost());
}
 
Example 5
Source File: RecyclerViewAdapter.java    From ExoPlayer-Wrapper with Apache License 2.0 6 votes vote down vote up
public void changeToNormalScreen() {
    ((Activity) mTextView.getContext()).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mLayouManager.enableScroll();

    RecyclerView.LayoutParams layoutParamsItem = (RecyclerView.LayoutParams) mView.getLayoutParams();
    layoutParamsItem.height = mItemHeight;
    layoutParamsItem.width = mItemWidth;
    layoutParamsItem.topMargin = mItemTopMargin;
    layoutParamsItem.bottomMargin = mItemBottomMargin;
    layoutParamsItem.leftMargin = mItemLeftMargin;
    layoutParamsItem.rightMargin = mItemRightMargin;
    mView.setLayoutParams(layoutParamsItem);

    ConstraintLayout.LayoutParams videoParams = (ConstraintLayout.LayoutParams) mExoPlayerView.getLayoutParams();
    videoParams.height = mVideoHeight;
    videoParams.width = mVideoWidth;
    //videoParams.bottomToBottom = 0;
    mExoPlayerView.setLayoutParams(videoParams);

    mTextView.setVisibility(View.VISIBLE);
}
 
Example 6
Source File: GuidanceNextManeuverView.java    From msdkui-android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets icon end margin.
 * @param margin integer to represent margin size.
 */
void setIconEndMargin(final int margin) {
    final ImageView iconView = findViewById(R.id.nextManeuverIconView);
    final ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams)
            iconView.getLayoutParams();
    layoutParams.setMarginEnd(margin);
}
 
Example 7
Source File: ConfigWizardBaseActivity.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Restores the default size of the white content area in tablet layouts
 */
private void showStandardTabletContentArea() {
    if (isPhoneLayout()) {
        return;
    }
    ConstraintLayout.LayoutParams guideLineTopParams = (ConstraintLayout.LayoutParams) guideline_top.getLayoutParams();
    guideLineTopParams.guidePercent = defaultGuidelineTopPercentage;
    guideline_top.setLayoutParams(guideLineTopParams);

    ConstraintLayout.LayoutParams guideLineBottomParams = (ConstraintLayout.LayoutParams) guideline_bottom.getLayoutParams();
    guideLineBottomParams.guidePercent = defaultGuidelineBottomPercentage;
    guideline_bottom.setLayoutParams(guideLineBottomParams);
}
 
Example 8
Source File: ConfigWizardBaseActivity.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Increases the white content area in tablet layouts
 */
private void showIncreasedTabletContentArea() {
    if (isPhoneLayout()) {
        return;
    }
    ConstraintLayout.LayoutParams guideLineTopParams = (ConstraintLayout.LayoutParams) guideline_top.getLayoutParams();
    float increasedTopPercentage = defaultGuidelineTopPercentage - GUIDE_LINE_COMPACT_DELTA;
    guideLineTopParams.guidePercent = increasedTopPercentage > 0f ? increasedTopPercentage : 0f;
    guideline_top.setLayoutParams(guideLineTopParams);

    ConstraintLayout.LayoutParams guideLineBottomParams = (ConstraintLayout.LayoutParams) guideline_bottom.getLayoutParams();
    float increasedBottomPercentage = defaultGuidelineBottomPercentage + GUIDE_LINE_COMPACT_DELTA;
    guideLineBottomParams.guidePercent = increasedBottomPercentage < 1f ? increasedBottomPercentage : 1f;
    guideline_bottom.setLayoutParams(guideLineBottomParams);
}
 
Example 9
Source File: BaseActivity.java    From Ruisi with Apache License 2.0 5 votes vote down vote up
protected void addToolbarView(View v) {
    ConstraintLayout toolbar = findViewById(R.id.myToolBar);
    if (toolbar != null) {
        ConstraintLayout.LayoutParams pls = new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
        v.setLayoutParams(pls);
        int padding = DimenUtils.dip2px(this, 12);
        v.setPadding(padding, padding, padding, padding);
        pls.setMarginEnd(padding);
        pls.bottomToBottom = ConstraintSet.PARENT_ID;
        pls.topToTop = ConstraintSet.PARENT_ID;
        pls.endToEnd = ConstraintSet.PARENT_ID;
        //pls.gravity = Gravity.END;
        toolbar.addView(v);
    }
}
 
Example 10
Source File: RecyclerViewAdapter.java    From ExoPlayer-Wrapper with Apache License 2.0 5 votes vote down vote up
public void changeToFullScreen() {
    mLayouManager.disableScroll();
    RecyclerView.LayoutParams layoutParamsItem = (RecyclerView.LayoutParams) mView.getLayoutParams();
    mItemHeight = layoutParamsItem.height;
    mItemWidth = layoutParamsItem.width;
    mItemTopMargin = layoutParamsItem.topMargin;
    mItemBottomMargin = layoutParamsItem.bottomMargin;
    mItemLeftMargin = layoutParamsItem.leftMargin;
    mItemRightMargin = layoutParamsItem.rightMargin;

    layoutParamsItem.height = ViewGroup.LayoutParams.MATCH_PARENT;
    layoutParamsItem.width = ViewGroup.LayoutParams.MATCH_PARENT;
    layoutParamsItem.topMargin = 0;
    layoutParamsItem.bottomMargin = 0;
    layoutParamsItem.leftMargin = 0;
    layoutParamsItem.rightMargin = 0;
    mView.setLayoutParams(layoutParamsItem);

    ConstraintLayout.LayoutParams videoParams = (ConstraintLayout.LayoutParams) mExoPlayerView.getLayoutParams();
    mVideoHeight = videoParams.height;
    mVideoWidth = videoParams.width;
    videoParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
    videoParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    //videoParams.bottomToBottom = R.id.parent;
    mExoPlayerView.setLayoutParams(videoParams);

    mExoPlayerView.post(new Runnable() {
        @Override
        public void run() {
            mLayouManager.scrollToPosition(getAdapterPosition());
        }
    });

    mTextView.setVisibility(View.GONE);

    ((Activity) mTextView.getContext()).setRequestedOrientation(SCREEN_ORIENTATION_LANDSCAPE);

}
 
Example 11
Source File: GuidanceNextManeuverViewTest.java    From msdkui-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testIconEndMargin() {
    mGuidanceNextManeuverView.setIconEndMargin(10);
    final ImageView iconView = mGuidanceNextManeuverView.findViewById(R.id.nextManeuverIconView);
    final ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams)
            iconView.getLayoutParams();
    assertThat(layoutParams.getMarginEnd(), equalTo(10));
}
 
Example 12
Source File: LegendView.java    From WidgetCase with Apache License 2.0 5 votes vote down vote up
/**
 * 动态计算列数
 */
private void autoCaclColumn() {
    if (getParent() instanceof ConstraintLayout) {
        ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) getLayoutParams();
        int margin = params.leftMargin + params.rightMargin;
        // 计算每行显示列数
        mColumn = (getMeasuredWidth() - margin) / mColumnWidth;
        LogUtil.logD("201812201056", "动态计算出的列数 = " + mColumn +
                "->MeasuredWidth = " + getMeasuredWidth() + "->margin = " + margin + "->left = " + getPaddingLeft() + "->right = " + getPaddingRight());
    } else {
        throw new IllegalArgumentException("外层布局需要使用ConstraintLayout");
    }
}
 
Example 13
Source File: GalleryActivity.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
private void instantiateWebView() {
    if(webView!=null)return;

    webView=(CustomWebView)getLayoutInflater().inflate(R.layout.custom_webview,masterLayout,false);
    webView.addFetcher((url, html) -> {
        /*Map<String,String> headers=new HashMap<>();
        headers.put("X-CSRFToken",fetchCSRF(html));
        headers.put("X-Requested-With", "XMLHttpRequest");
        if(html.contains("Unfavorite")){
            webView.loadUrl("https://nhentai.net/api/gallery/"+gallery.getId()+"/favorite",headers);
            updateIcon(true);
        }else{
            webView.loadUrl("https://nhentai.net/api/gallery/"+gallery.getId()+"/unfavorite",headers);
            updateIcon(false);
        }*/
    });

    ConstraintLayout.LayoutParams params=new ConstraintLayout.LayoutParams(webView.getLayoutParams());
    params.topToBottom=R.id.parent;
    params.bottomToBottom=R.id.parent;
    params.startToStart=R.id.parent;
    params.endToEnd=R.id.parent;
    params.width= ConstraintLayout.LayoutParams.MATCH_PARENT;
    params.height= ConstraintLayout.LayoutParams.MATCH_PARENT;
    webView.setLayoutParams(params);
    masterLayout.addView(webView);
}
 
Example 14
Source File: Helper.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
static void hide(View view) {
    view.setPadding(0, 0, 0, 0);

    ViewGroup.LayoutParams lparam = view.getLayoutParams();
    lparam.width = 0;
    lparam.height = 0;
    if (lparam instanceof ConstraintLayout.LayoutParams)
        ((ConstraintLayout.LayoutParams) lparam).setMargins(0, 0, 0, 0);
    view.setLayoutParams(lparam);
}
 
Example 15
Source File: BottomCardView.java    From mapwize-ui-android with MIT License 5 votes vote down vote up
private void hideDetails() {
    ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) this.getLayoutParams();
    lp.height = LayoutParams.WRAP_CONTENT;
    this.setLayoutParams(lp);
    closeDetailsButton.setVisibility(View.GONE);
    listener.onDetailsClose();
}
 
Example 16
Source File: BottomCardView.java    From mapwize-ui-android with MIT License 5 votes vote down vote up
private void showDetails() {
    ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) this.getLayoutParams();
    lp.height = LayoutParams.MATCH_PARENT;
    this.setLayoutParams(lp);
    closeDetailsButton.setVisibility(View.VISIBLE);
    objectInfoFrameLayout.setVisibility(View.VISIBLE);
    listener.onDetailsOpen();
}
 
Example 17
Source File: VideoDetailActivity.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
private void toggleFullScreen() {
    ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) videoPlayer.getLayoutParams();
    if (layoutParams != null) {
        if (layoutParams.width == ViewGroup.LayoutParams.MATCH_PARENT
                && layoutParams.height == ViewGroup.LayoutParams.MATCH_PARENT) {
            layoutParams.width = FontDisplayUtil.dip2px(VideoDetailActivity.this, 420);
            layoutParams.height = FontDisplayUtil.dip2px(VideoDetailActivity.this, 237);

            layoutParams.leftMargin = FontDisplayUtil.dip2px(VideoDetailActivity.this, 48);
            layoutParams.topMargin = FontDisplayUtil.dip2px(VideoDetailActivity.this, 74);
            layoutParams.rightMargin = 0;
            layoutParams.bottomMargin = 0;
            int padding = FontDisplayUtil.dip2px(VideoDetailActivity.this, 2);
            videoPlayer.setPadding(padding, padding, padding, padding);
            isFullScreen = false;
        } else {
            layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
            layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
            layoutParams.leftMargin = 0;
            layoutParams.topMargin = 0;
            layoutParams.rightMargin = 0;
            layoutParams.bottomMargin = 0;
            isFullScreen = true;
            videoPlayer.setPadding(0, 0, 0, 0);
        }
        videoPlayer.setLayoutParams(layoutParams);
    }
}
 
Example 18
Source File: ZoomActivity.java    From NClientV2 with Apache License 2.0 4 votes vote down vote up
private void applyMargin(boolean landscape,View view){
    ConstraintLayout.LayoutParams lp= (ConstraintLayout.LayoutParams) view.getLayoutParams();
    lp.setMargins(0,0,landscape||hardwareKeys()?Global.getNavigationBarHeight(this):0,0);
    view.setLayoutParams(lp);
}
 
Example 19
Source File: ConfigWizardBaseActivity.java    From bitmask_android with GNU General Public License v3.0 4 votes vote down vote up
private void setDefaultGuidelineValues() {
    if (isTabletLayout()) {
        defaultGuidelineTopPercentage = ((ConstraintLayout.LayoutParams) guideline_top.getLayoutParams()).guidePercent;
        defaultGuidelineBottomPercentage = ((ConstraintLayout.LayoutParams) guideline_bottom.getLayoutParams()).guidePercent;
    }
}
 
Example 20
Source File: StreamFragment.java    From Twire with GNU General Public License v3.0 4 votes vote down vote up
private void setupLandscapeChat() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && settings.isChatLandscapeSwipable() && settings.isChatInLandscapeEnabled()) {
        final int width = getScreenRect(getActivity()).height();

        View.OnTouchListener touchListener = new View.OnTouchListener() {
            private int downPosition = width;
            private int widthOnDown = width;

            public boolean onTouch(View view, MotionEvent event) {
                if (isLandscape) {
                    final int X = (int) event.getRawX();
                    switch (event.getAction() & MotionEvent.ACTION_MASK) {
                        case MotionEvent.ACTION_DOWN:
                            ConstraintLayout.LayoutParams lParams = (ConstraintLayout.LayoutParams) mVideoWrapper.getLayoutParams();
                            if (lParams.width > 0)
                                widthOnDown = lParams.width;

                            downPosition = (int) event.getRawX();
                            break;
                        case MotionEvent.ACTION_UP:
                            int upPosition = (int) event.getRawX();
                            int deltaPosition = upPosition - downPosition;

                            if (deltaPosition < 20 && deltaPosition > -20) {
                                return false;
                            }

                            if (upPosition < downPosition) {
                                showLandscapeChat();
                            } else {
                                hideLandscapeChat();
                            }

                            break;
                        case MotionEvent.ACTION_MOVE:
                            ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) mVideoWrapper.getLayoutParams();
                            int newWidth;

                            if (X > downPosition) { // Swiping right
                                newWidth = widthOnDown + (X - downPosition);
                            } else { // Swiping left
                                newWidth = widthOnDown - (downPosition - X);
                            }

                            layoutParams.width = Math.max(Math.min(newWidth, width), width - getLandscapeChatTargetWidth());

                            mVideoWrapper.setLayoutParams(layoutParams);
                            break;

                    }
                    rootView.invalidate();
                }
                return false;
            }
        };

        mVideoWrapper.setOnTouchListener(touchListener);
        mClickIntercepter.setOnTouchListener(touchListener);
    }
}