An easier way to add, remove and edit constraints and another ConstraintLayout properties;
Add this dependency from jCenter:
implementation "com.gustavofao:ConstraintUtils:$CONSTRAINT_UTILS_VERSION"
Our latest version is:
import com.faogustavo.constraint.utils.modify
constraintLayout.modify {
// Do your changes here
}
constraintLayout.modify {
on(backgroundImage) {
bottomToBottomOf(this.parent)
}
on(title) {
unbind(ConstraintViewEditor.Side.LEFT)
rightToLeftOf(this.parent, 16.dp)
}
on(description) {
unbind(ConstraintViewEditor.Side.BOTTOM)
topToBottomOf(this.parent)
}
...
}
constraintLayout.modify {
...
// Use the default transition type
animated()
// Or use a custom one
val transition = ChangeBounds().apply {
interpolator = BounceInterpolator()
duration = 1200
}
withTransition(transition)
}
This is the simple way to start a modification on your constraint layout. Inside the block, you will have access to functions that allows you to modificate your view/views and animate the transaction;
This is another way to start a modification. Passing the layout id as parameter allow you to clone the constraints from another layout;
Start to modify a child view from a constraint layout;
Same from the method above, but using the ID instead of the view;
Use the basic animation on the update from the view constraints;
Use a custom transition to animate the changes. You can also use a transition set. See the Transition docs;
This attribute from the ConstraintViewEditor is the ID of the constraint layout (aka parent of inner views);
Remove one or more constraints from the view. Calling without a parameter will remove all constraints;
Bind the top of the editing view to the top of anotherView;
Bind the top of the editing view to the bottom of anotherView;
bottomToBottomOf(anotherView: View, margin: Int)
and bottomToBottomOf(anotherView: Int, margin: Int)
Bind the bottom of the editing view to the bottom of anotherView;
Bind the bottom of the editing view to the top of anotherView;
Bind the left of the editing view to the left of anotherView;
Bind the left of the editing view to the right of anotherView;
Bind the right of the editing view to the right of anotherView;
Bind the right of the editing view to the left of anotherView;
Bind the top and bottom from the editing view to the top and bottom from the anotherView;
Bind the left and right from the editing view to the left and right from the anotherView;
Sets a specific width to the view;
Sets a specific height to the view;
Matchs the width with the parents width;
Matchs the height with the parents height;
Makes the view width the maximum allowed by the constraints;
Makes the view height the maximum allowed by the constraints;
Makes the view width the minimum necessary by the view;
Makes the view height the minimum necessary by the view;
Determines a minimum width to the view;
Determines a minimum height to the view;
Determines a maximum width to the view;
Determines a maximum height to the view;
Set the views rotation. Rotation should be from 0 to 360;
Set the bias from the view. Bias should be from 0 to 1;
Set the bias from the view. Bias should be from 0 to 1;
Set the ratio from the view. Width or height sould (at least one of them) must be matchConstraint; Value should be in this format: width:height
. eg: 4:3;
Set the view elevation;
circleTo(anotherView: View, angle: Float, radius: Int)
and circleTo(anotherView: Int, angle: Float, radius: Int)
Align this view in a circle position to another one. The angle should be between 0 and 360;
centerCircleWithIdTo(othersViews: List<View>, radius: Int, rangeInitial: Int, rangeFinal: Int)
and centerCircleWithIdTo(anothersViews: List<Int>, radius: Int, rangeInitial: Int, rangeFinal: Int)
Distribuite the views equally in the range defined. The initial and final range position must be between 0 and 360.
- General
- Easy way to use
- Use views or ids to execute the bindings
- Possibility to animate
- Basic animation
- Work with single views
- Constraints and margins
- Unbind constraint (All/Top/Bottom/Right/Left)
- Top to top of
- Top to bottom of
- Bottom to bottom of
- Bottom to top of
- Left to left of
- Left to right of
- Right to right of
- Right to left of
- Align center vertically with another view
- Align center horizontally with another view
- Circular to another with radius and angle
- Sizes
- Height/Width
- Min/Max
- WrapConstraint/WrapContent
- Ratio
- Rotation
- Bias
- Visibility
- Constraints and margins
- Work with group of views
- Circular constraint
- Barriers
- Guidelines
- Groups
Copyright 2019 Gustavo Fão. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.