How to use constraint attributes in style?
When I'm trying to use it as any other attributes with custom namespace it's has no effect on my view.
<style name="Header.Center" parent="Header">
<item name="layout_constraintBottom_toBottomOf">parent</item>
</style>
Adding namespace app: is not helping.
The TextView above has three types of handles: Resize handle - It's present on the four corners and is used to resize the view, but keeping its constraints intact. Side handle - It's the circular handle present on the centre of each side. It's used to set the top, left, bottom and right constraints of the view.
Layout with 2 views on different sides. Results show that the fastest layout is Relative Layout, but difference between this and Linear Layout is really small, what we can't say about Constraint Layout. More complex layout but results are the same, flat Constraint Layout is slower than nested Linear Layout.
You can use a ConstraintLayout in an other ConstraintLayout but you need to respect some rules. All direct childs of a ConstraintLayout should have constraint on left,top, right and bottom.
First of all, make sure that the View
that you're applying the style on is a direct child of the ConstraintLayout
. Otherwise, the constraints will not be taken into account when positioning the View
.
I have tried it and the way you tried does in fact work. I have added the following style to the styles.xml
:
<style name="CustomStyle">
<item name="layout_constraintBottom_toBottomOf">parent</item>
<item name="layout_constraintEnd_toEndOf">parent</item>
</style>
Created a basic layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/CustomStyle"/>
</android.support.constraint.ConstraintLayout>
And it does indeed position the TextView
at the bottom right corner of the parent.
maybe your view's attribute is "match_parent",but it is wrong. It should be "wrap_content".
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/CustomStyle"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With