Created
May 2, 2018 02:27
-
-
Save Gryzor/a37202d49d3ded4f3a5f5e26166dc40f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ProgressConstraintLayout(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
configureViews(); | |
} | |
private void configureViews() { | |
// Create a Constraint Set and clone our constraints | |
ConstraintSet constraintSet = new ConstraintSet(); | |
constraintSet.clone(this); | |
// Create our progress bar… | |
ProgressBar progressBar = new ProgressBar(getContext(), null, android.R.attr.progressBarStyleLarge); | |
progressBar.setIndeterminate(true); | |
progressBar.setId(generateViewId()); | |
// add it to our hierarchy | |
addView(progressBar, new ConstraintLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); | |
// Configure its constraints … basically pin it to every side. | |
constraintSet.connect(progressBar.getId(), ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP); | |
constraintSet.connect(progressBar.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM); | |
constraintSet.connect(progressBar.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START); | |
constraintSet.connect(progressBar.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END); | |
// now apply the new constraints (This will not work, by the way) ;) | |
constraintSet.applyTo(this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment