Java Code Examples for android.support.constraint.ConstraintLayout#LayoutParams

The following examples show how to use android.support.constraint.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: ToolbarHelper.java    From WanAndroid with GNU General Public License v3.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 += ScreenUtils.getStatusHeight(view.getContext());
    } else if (params instanceof FrameLayout.LayoutParams) {
        FrameLayout.LayoutParams frameParams = (FrameLayout.LayoutParams) params;
        frameParams.topMargin += ScreenUtils.getStatusHeight(view.getContext());
    } else if (params instanceof RelativeLayout.LayoutParams) {
        RelativeLayout.LayoutParams relativeParams = (RelativeLayout.LayoutParams) params;
        relativeParams.topMargin += ScreenUtils.getStatusHeight(view.getContext());
    } else if (params instanceof ConstraintLayout.LayoutParams) {
        ConstraintLayout.LayoutParams constraintParams = (ConstraintLayout.LayoutParams) params;
        constraintParams.topMargin += ScreenUtils.getStatusHeight(view.getContext());
    }
    view.setLayoutParams(params);
}
 
Example 2
Source File: NewsView.java    From CryptoBuddy with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void inflateComponents(){
    inflate(getContext(), R.layout.row_news_item, this);
    articleTitleTextView = findViewById(R.id.articleTitle);
    ageTextView = findViewById(R.id.age);
    articleImageView = findViewById(R.id.articleImage);
    sourceNameTextView = findViewById(R.id.sourceName);
    setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent browserIntent = new Intent(getContext(), WebViewActivity.class);
            browserIntent.putExtra("url", newsItem.articleURL);
            browserIntent.putExtra("title", "News");
            getContext().startActivity(browserIntent);
        }
    });
    ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.orientation = LayoutParams.VERTICAL;
    setLayoutParams(params);
    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    setBackgroundResource(outValue.resourceId);
    setFocusable(true);
    setClickable(true);
}
 
Example 3
Source File: PlaybackView.java    From justaline-android with Apache License 2.0 5 votes vote down vote up
private void init() {

        inflate(getContext(), R.layout.view_playback, this);

        setBackgroundColor(Color.BLACK);

        mAnalytics = Fa.get();

        TextureView mVideoTextureView = findViewById(R.id.video);
        mVideoTextureView.setSurfaceTextureListener(this);

        findViewById(R.id.close_button).setOnClickListener(this);
        findViewById(R.id.layout_share).setOnClickListener(this);
        findViewById(R.id.layout_save).setOnClickListener(this);

        // set margin of bottom icons to be appropriate size for screen
        View saveLayout = findViewById(R.id.layout_save);
        ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) saveLayout
                .getLayoutParams();
        layoutParams.bottomMargin = getHeightOfNavigationBar();
        saveLayout.setLayoutParams(layoutParams);

        View shareLayout = findViewById(R.id.layout_share);
        layoutParams = (ConstraintLayout.LayoutParams) shareLayout.getLayoutParams();
        layoutParams.bottomMargin = getHeightOfNavigationBar();
        shareLayout.setLayoutParams(layoutParams);

        mAudioAttributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_MEDIA)
                .setContentType(AudioAttributes.CONTENT_TYPE_MOVIE)
                .build();

    }
 
Example 4
Source File: MainActivity.java    From AlipayPullRefresh with Apache License 2.0 5 votes vote down vote up
/**
 * 沉浸式状态栏
 */
private void adjustStatusBar() {
    boolean immerse = Utils.immerseStatusBar(this);
    View statusBarView = findViewById(R.id.home_status_view);
    if (immerse) {
        ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) statusBarView.getLayoutParams();
        lp.height = Utils.getStatusBarHeight(this);
        statusBarView.setLayoutParams(lp);
    } else {
        statusBarView.setVisibility(View.GONE);
    }
}
 
Example 5
Source File: InstructionView.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
/**
 * Adjust the banner text layout {@link ConstraintLayout} vertical bias.
 *
 * @param percentBias to be set to the text layout
 */
private void adjustBannerTextVerticalBias(float percentBias) {
  int orientation = getContext().getResources().getConfiguration().orientation;
  if (orientation == Configuration.ORIENTATION_PORTRAIT) {
    ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) instructionLayoutText.getLayoutParams();
    params.verticalBias = percentBias;
    instructionLayoutText.setLayoutParams(params);
  }
}
 
Example 6
Source File: InstructionViewHolder.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void adjustBannerVerticalBias(float percentBias) {
  int orientation = itemView.getResources().getConfiguration().orientation;
  if (orientation == Configuration.ORIENTATION_PORTRAIT) {
    ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) instructionLayoutText.getLayoutParams();
    params.verticalBias = percentBias;
    instructionLayoutText.setLayoutParams(params);
  }
}
 
Example 7
Source File: MainActivity.java    From AlipayPullRefresh with Apache License 2.0 5 votes vote down vote up
/**
 * 沉浸式状态栏
 */
private void adjustStatusBar() {
    boolean immerse = Utils.immerseStatusBar(this);
    View statusBarView = findViewById(R.id.home_status_view);
    if (immerse) {
        ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) statusBarView.getLayoutParams();
        lp.height = Utils.getStatusBarHeight(this);
        statusBarView.setLayoutParams(lp);
    } else {
        statusBarView.setVisibility(View.GONE);
    }
}
 
Example 8
Source File: SignUpFragment.java    From android-login with MIT License 5 votes vote down vote up
private void foldStuff() {
  caption.setTextSize(TypedValue.COMPLEX_UNIT_PX, caption.getTextSize() / 2f);
  caption.setTextColor(Color.WHITE);
  ConstraintLayout.LayoutParams params = getParams();
  params.rightToRight = ConstraintLayout.LayoutParams.UNSET;
  params.verticalBias = 0.5f;
  caption.setLayoutParams(params);
}
 
Example 9
Source File: OrderDialogFragment.java    From From-design-to-Android-part1 with Apache License 2.0 5 votes vote down vote up
private static ConstraintLayout.LayoutParams startColorParams(View selectedView) {
    final int colorSize = selectedView.getContext().getResources()
        .getDimensionPixelOffset(R.dimen.product_color_size);

    final ConstraintLayout.LayoutParams layoutParams =
        new ConstraintLayout.LayoutParams(colorSize, colorSize);

    setStartState(selectedView, layoutParams);
    return layoutParams;
}
 
Example 10
Source File: OrderDialogFragment.java    From From-design-to-Android-part1 with Apache License 2.0 5 votes vote down vote up
private static ConstraintLayout.LayoutParams startTextParams(View selectedView) {
    final ConstraintLayout.LayoutParams layoutParams =
        new ConstraintLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    setStartState(selectedView, layoutParams);
    return layoutParams;
}
 
Example 11
Source File: OrderDialogFragment.java    From From-design-to-Android-part1 with Apache License 2.0 5 votes vote down vote up
private static ConstraintLayout.LayoutParams endParams(View v, View targetView) {
    final ConstraintLayout.LayoutParams layoutParams =
        (ConstraintLayout.LayoutParams) v.getLayoutParams();

    final int marginLeft = v.getContext().getResources()
        .getDimensionPixelOffset(R.dimen.spacing_medium);

    layoutParams.setMargins(marginLeft, 0, 0, 0);
    layoutParams.topToTop = targetView.getId();
    layoutParams.startToEnd = targetView.getId();
    layoutParams.bottomToBottom = targetView.getId();

    return layoutParams;
}
 
Example 12
Source File: KeyboardDismisser.java    From keyboard-dismisser with Apache License 2.0 4 votes vote down vote up
private static void swapMainLayoutWithDismissingLayout(ViewGroup viewGroup, Activity activity) {
    if (viewGroup == null) {
        return;
    }

    String className = "";

    String viewGroupClassName = viewGroup.getClass().getSimpleName();
    for (String name : sSupportedClasses) {
        if (viewGroupClassName.equals(name)) {
            className = name;
        }
    }

    ViewGroup generatedLayout = viewGroup;

    switch (className) {
        case "LinearLayout":
            generatedLayout = new KeyboardDismissingLinearLayout(activity);
            break;
        case "RelativeLayout":
            generatedLayout = new KeyboardDismissingRelativeLayout(activity);
            break;
        case "CoordinatorLayout":
            generatedLayout = new KeyboardDismissingCoordinatorLayout(activity);
            break;
        case "ConstraintLayout":
            generatedLayout = new KeyboardDismissingConstraintLayout(activity);
    }

    if (className.isEmpty()) {
        return;
    }

    if (viewGroup.getLayoutParams() != null) {
        generatedLayout.setLayoutParams(viewGroup.getLayoutParams());
    } else {
        generatedLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }

    if (generatedLayout instanceof KeyboardDismissingConstraintLayout) {
        int widthOfOriginalLayout = ConstraintLayout.LayoutParams.MATCH_PARENT;
        int heightOfOriginalLayout = ConstraintLayout.LayoutParams.MATCH_PARENT;

        if (viewGroup.getLayoutParams() != null) {
            widthOfOriginalLayout = viewGroup.getLayoutParams().width;
            heightOfOriginalLayout = viewGroup.getLayoutParams().height;
        }

        ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(widthOfOriginalLayout, heightOfOriginalLayout);
        layoutParams.validate();

        generatedLayout.setLayoutParams(layoutParams);
    }

    while (viewGroup.getChildCount() != 0) {
        View child = viewGroup.getChildAt(0);

        viewGroup.removeViewAt(0);
        generatedLayout.addView(child);
    }

    viewGroup.removeAllViews();
    viewGroup.addView(generatedLayout, 0);
}
 
Example 13
Source File: AuthFragment.java    From android-login with MIT License 4 votes vote down vote up
protected ConstraintLayout.LayoutParams getParams() {
  return ConstraintLayout.LayoutParams.class.cast(caption.getLayoutParams());
}
 
Example 14
Source File: OrderDialogFragment.java    From From-design-to-Android-part1 with Apache License 2.0 4 votes vote down vote up
private static void setStartState(View selectedView, ConstraintLayout.LayoutParams layoutParams) {
    layoutParams.topToTop = ((ViewGroup) selectedView.getParent().getParent()).getId();
    layoutParams.leftToLeft = ((ViewGroup) selectedView.getParent().getParent()).getId();
    layoutParams.setMargins((int) selectedView.getX(), (int) selectedView.getY(), 0, 0);
}
 
Example 15
Source File: NoInternetDialog.java    From NoInternetDialog with Apache License 2.0 4 votes vote down vote up
private void initGuideLine() {
    ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) topGuide.getLayoutParams();
    lp.guidePercent = isHalloween ? 0.34f : 0.3f;
    topGuide.setLayoutParams(lp);
}
 
Example 16
Source File: SendFragment.java    From nano-wallet-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@BindingAdapter("layout_constraintGuide_percent")
public static void setLayoutConstraintGuidePercent(Guideline guideline, float percent) {
    ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) guideline.getLayoutParams();
    params.guidePercent = percent;
    guideline.setLayoutParams(params);
}
 
Example 17
Source File: VideoControllerView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
private void resetControllerParams() {
    ConstraintLayout.LayoutParams progressParams = (ConstraintLayout.LayoutParams)
            mVerticalProgress.getLayoutParams();
    ConstraintLayout.LayoutParams pauseParams = (ConstraintLayout.LayoutParams) mPauseButton
            .getLayoutParams();
    ConstraintLayout.LayoutParams timeParams = (ConstraintLayout.LayoutParams) mEndTime
            .getLayoutParams();
    ConstraintLayout.LayoutParams changeIconParams = (ConstraintLayout.LayoutParams)
            mScreenChangeView.getLayoutParams();

    LayoutParams params = (LayoutParams) mVerticalController.getLayoutParams();
    if (!VenvyUIUtil.isScreenOriatationPortrait(mContext)) {
        params.height = (int) getResources().getDimension(R.dimen.media_controller_height);
        params.gravity = Gravity.BOTTOM;

        pauseParams.topToTop = ConstraintLayout.LayoutParams.UNSET;
        pauseParams.bottomMargin = (int) getResources().getDimension(R.dimen
                .media_controller_pause_margin_bottom);

        changeIconParams.rightMargin = (int) getResources().getDimension(R.dimen
                .media_play_margin_land_left);
        changeIconParams.bottomMargin = (int) getResources()
                .getDimension(R.dimen.media_controller_pause_margin_bottom);
        changeIconParams.topToTop = ConstraintLayout.LayoutParams.UNSET;

        timeParams.rightToLeft = ConstraintLayout.LayoutParams.UNSET;
        timeParams.leftToRight = R.id.tv_media_time_current;

        progressParams.bottomToBottom = ConstraintLayout.LayoutParams.UNSET;
        progressParams.leftToLeft = ConstraintLayout.LayoutParams.PARENT_ID;
        progressParams.rightToRight = ConstraintLayout.LayoutParams.PARENT_ID;
        progressParams.leftToRight = ConstraintLayout.LayoutParams.UNSET;
        progressParams.rightToLeft = ConstraintLayout.LayoutParams.UNSET;

    } else {
        params.height = (int) getResources().getDimension(R.dimen.media_controller_ver_height);
        params.gravity = Gravity.TOP;
        params.topMargin = VenvyUIUtil.dip2px(getContext(), 195) - params.height;

        pauseParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
        pauseParams.bottomMargin = 0;

        changeIconParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
        changeIconParams.bottomMargin = 0;
        changeIconParams.rightMargin = (int) getResources().getDimension(R.dimen
                .media_play_margin_left);

        timeParams.leftToRight = ConstraintLayout.LayoutParams.UNSET;
        timeParams.rightToLeft = mScreenChangeView.getId();

        progressParams.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
        progressParams.leftToRight = mCurrentTime.getId();
        progressParams.rightToLeft = mEndTime.getId();
        progressParams.leftToLeft = ConstraintLayout.LayoutParams.UNSET;
        progressParams.rightToRight = ConstraintLayout.LayoutParams.UNSET;
    }

    mPauseButton.setLayoutParams(pauseParams);
    mScreenChangeView.setLayoutParams(changeIconParams);
    mEndTime.setLayoutParams(timeParams);
    mVerticalProgress.setLayoutParams(progressParams);
    mVerticalController.setLayoutParams(params);
}