Java Code Examples for androidx.constraintlayout.widget.ConstraintSet#constrainHeight()

The following examples show how to use androidx.constraintlayout.widget.ConstraintSet#constrainHeight() . 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: ScrollingHelper.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
private void setArrowsVisibility(boolean visible) {
    final int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, visible ? verticalScrollerLength : 0, displayMetrics);

    ConstraintSet constraintSet = new ConstraintSet();
    if (whereBar == RIGHT) {
        constraintSet.constrainHeight(childId, ConstraintSet.MATCH_CONSTRAINT);
        constraintSet.constrainWidth(childId, ConstraintSet.MATCH_CONSTRAINT);
        constraintSet.connect(childId, ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT);
        constraintSet.connect(childId, ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT);
        constraintSet.connect(childId, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP);
        constraintSet.connect(childId, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM);
        constraintSet.setMargin(childId, ConstraintSet.RIGHT, width);

        constraintSet.constrainHeight(containerId, ConstraintSet.MATCH_CONSTRAINT);
        constraintSet.constrainWidth(containerId, width);
        constraintSet.connect(containerId, ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT);
        constraintSet.connect(containerId, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP);
        constraintSet.connect(containerId, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM);

    } else {
        constraintSet.constrainHeight(childId, ConstraintSet.MATCH_CONSTRAINT);
        constraintSet.constrainWidth(childId, ConstraintSet.MATCH_CONSTRAINT);
        constraintSet.connect(childId, ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT);
        constraintSet.connect(childId, ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT);
        constraintSet.connect(childId, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP);
        constraintSet.connect(childId, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM);
        constraintSet.setMargin(childId, ConstraintSet.LEFT, width);

        constraintSet.constrainHeight(containerId, ConstraintSet.MATCH_CONSTRAINT);
        constraintSet.constrainWidth(containerId, width);
        constraintSet.connect(containerId, ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT);
        constraintSet.connect(containerId, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP);
        constraintSet.connect(containerId, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM);

    }
    constraintSet.applyTo(this);

}
 
Example 2
Source File: ScrollingHelper.java    From BaldPhone with Apache License 2.0 4 votes vote down vote up
@Override
    public void onViewAdded(View child) {
        super.onViewAdded(child);
        if (aViewAdded || gone) {
            int id = child.getId();
            ConstraintSet constraintSet = new ConstraintSet();
//            constraintSet.clone(this);
            constraintSet.constrainHeight(id, ConstraintSet.MATCH_CONSTRAINT);
            constraintSet.constrainWidth(id, ConstraintSet.MATCH_CONSTRAINT);
            constraintSet.connect(id, ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT);
            constraintSet.connect(id, ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT);
            constraintSet.connect(id, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP);
            constraintSet.connect(id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM);
            constraintSet.setElevation(id, 2);
            constraintSet.setTranslationZ(id, 2);

            constraintSet.applyTo(this);

            if (aViewAdded)
                return;

        }
        aViewAdded = true;

        this.child = getChildAt(0);
        if (!(this.child instanceof Modular) && !programmerAwareOfUsingNonModularViews) {
            throw new IllegalArgumentException("not modular view inside a scrollingHelper");
        }
        if (child instanceof ModularRecyclerView) {
            if (emptyView == null) {
                this.emptyView = layoutInflater.inflate(R.layout.empty_view, this, false);
                super.addView(emptyView);
            }

        }

        if (!gone) {
            childId = child.getId();
            if (childId == View.NO_ID) {
                child.setId(childId = R.id.child);
            }
            scrollerHandler();
        }

    }
 
Example 3
Source File: VideoFragment.java    From googleads-ima-android with Apache License 2.0 4 votes vote down vote up
private void initUi(View rootView) {
  VideoPlayerWithAdPlayback mVideoPlayerWithAdPlayback =
      rootView.findViewById(R.id.videoPlayerWithAdPlayback);
  View playButton = rootView.findViewById(R.id.playButton);
  View playPauseToggle = rootView.findViewById(R.id.videoContainer);
  ViewGroup companionAdSlot = rootView.findViewById(R.id.companionAdSlot);
  mVideoTitle = rootView.findViewById(R.id.video_title);
  mVideoExampleLayout = rootView.findViewById(R.id.videoExampleLayout);
  mVideoExampleLayout.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
  mVideoExampleLayout.setSmoothScrollingEnabled(true);

  // Make the dummyScrollContent height the size of the screen height.
  DisplayMetrics displayMetrics = new DisplayMetrics();
  getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
  ConstraintLayout constraintLayout = rootView.findViewById(R.id.constraintLayout);
  ConstraintSet forceHeight = new ConstraintSet();
  forceHeight.clone(constraintLayout);
  forceHeight.constrainHeight(R.id.dummyScrollContent, displayMetrics.heightPixels);
  forceHeight.applyTo(constraintLayout);

  final TextView logText = rootView.findViewById(R.id.logText);

  // Provide an implementation of a logger so we can output SDK events to the UI.
  VideoPlayerController.Logger logger =
      new VideoPlayerController.Logger() {
        @Override
        public void log(String message) {
          Log.i("ImaExample", message);
          if (logText != null) {
            logText.append(message);
          }
        }
      };

  mVideoPlayerController =
      new VideoPlayerController(
          this.getActivity(),
          mVideoPlayerWithAdPlayback,
          playButton,
          playPauseToggle,
          getString(R.string.ad_ui_lang),
          companionAdSlot,
          logger);

  // If we've already selected a video, load it now.
  if (mVideoItem != null) {
    loadVideo(mVideoItem);
  }
}