gpt4 book ai didi

android - 样式中的 ConstraintLayout 约束属性

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:01:55 25 4
gpt4 key购买 nike

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

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

 <style name="Header.Center" parent="Header">
<item name="layout_constraintBottom_toBottomOf">parent</item>
</style>

添加命名空间 app: 没有帮助。

最佳答案

首先,确保要应用样式的 ViewConstraintLayout 的直接子级。否则,在定位 View 时将不会考虑约束。

我试过了,你试过的方法确实有效。我已将以下样式添加到 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 定位在父级的右下角。

关于android - 样式中的 ConstraintLayout 约束属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51049653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com