Android ConstraintLayout样式中的约束属性
如何在样式中使用约束属性 当我尝试将它用作任何其他具有自定义命名空间的属性时,它对我的视图没有任何影响Android ConstraintLayout样式中的约束属性,android,Android,如何在样式中使用约束属性 当我尝试将它用作任何其他具有自定义命名空间的属性时,它对我的视图没有任何影响 父母亲 添加名称空间应用程序:没有帮助。首先,确保应用样式的视图是约束列表的直接子视图。否则,在定位视图时将不考虑约束 我已经试过了,而你试过的方法确实有效。我已将以下样式添加到styles.xml: <style name="CustomStyle"> <item name="layout_constraintBottom_toBottomOf">pare
父母亲
添加名称空间应用程序:没有帮助。首先,确保应用样式的
视图是约束列表的直接子视图。否则,在定位视图时将不考虑约束
我已经试过了,而你试过的方法确实有效。我已将以下样式添加到styles.xml
:
<style name="CustomStyle">
<item name="layout_constraintBottom_toBottomOf">parent</item>
<item name="layout_constraintEnd_toEndOf">parent</item>
</style>
父母亲
父母亲
创建基本布局:
<?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>
它确实将TextView
定位在父视图的右下角。也许视图的属性是“匹配父视图”,但它是错误的。
它应该是“包装内容”
对于我来说,实际删除应用程序:使其正常工作;离开它会让布局表现得很奇怪我试过了,我觉得效果不错。但是,在布局xml中,虽然它确实正确对齐了视图,但仍会显示警告,说明您必须“添加约束,否则视图将在运行时放在左上角”。我建议在android studio正确支持之前不要这样做。如果您确保约束正常工作,还可以向父约束布局添加工具:ignore=“missingstraints”。
<TextView
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/CustomStyle"/>