ConstraintLayout约束属性的样式

cza*_*666 9 android

如何在样式中使用约束属性?

当我尝试将其用作具有自定义命名空间的任何其他属性时,它对我的​​视图没有影响.

 <style name="Header.Center" parent="Header">
    <item name="layout_constraintBottom_toBottomOf">parent</item>
 </style>
Run Code Online (Sandbox Code Playgroud)

添加命名空间应用程序:没有帮助.

Paw*_*ski 12

首先,确保View你正在应用风格的是直接的孩子ConstraintLayout.否则,定位时不会考虑约束View.

我已经尝试过了,你尝试的方式确实有效.我已将以下样式添加到styles.xml:

<style name="CustomStyle">
    <item name="layout_constraintBottom_toBottomOf">parent</item>
    <item name="layout_constraintEnd_toEndOf">parent</item>
</style>
Run Code Online (Sandbox Code Playgroud)

创建了一个基本布局:

<?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>
Run Code Online (Sandbox Code Playgroud)

它确实位于TextView父母的右下角.

  • 对我来说,实际上删除 *app:* 使它起作用;离开它会使布局表现得很奇怪 (2认同)