Android 取消设置ConstraintLayout xml中的属性
我有一个默认Android 取消设置ConstraintLayout xml中的属性,android,xml,android-constraintlayout,Android,Xml,Android Constraintlayout,我有一个默认ConstraintLayout行为的样式。现在我想重置layout\u constraintTop\u toTopOf属性,以便使用layout\u constraintTop\u toBottomOf获得正确的约束。如何从视图中删除layout\u constraintop\u topof styles.xml: <style name="ConstraintDefault"> <item name="android:layout_width">0
ConstraintLayout
行为的样式。现在我想重置layout\u constraintTop\u toTopOf
属性,以便使用layout\u constraintTop\u toBottomOf
获得正确的约束。如何从视图中删除layout\u constraintop\u topof
styles.xml:
<style name="ConstraintDefault">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">0dp</item>
<item name="layout_constraintBottom_toBottomOf">parent</item>
<item name="layout_constraintEnd_toEndOf">parent</item>
<item name="layout_constraintStart_toStartOf">parent</item>
<item name="layout_constraintTop_toTopOf">parent</item>
</style>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/include_toolbar"
layout="@layout/layout_toolbar" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvDummy"
style="@style/ConstraintDefault"
app:layout_constraintTop_toBottomOf="@id/include_toolbar" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
style="@style/Fab"
app:srcCompat="@drawable/ic_add" />
</android.support.constraint.ConstraintLayout>
0dp
0dp
父母亲
父母亲
父母亲
父母亲
main\u layout.xml:
<style name="ConstraintDefault">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">0dp</item>
<item name="layout_constraintBottom_toBottomOf">parent</item>
<item name="layout_constraintEnd_toEndOf">parent</item>
<item name="layout_constraintStart_toStartOf">parent</item>
<item name="layout_constraintTop_toTopOf">parent</item>
</style>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/include_toolbar"
layout="@layout/layout_toolbar" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvDummy"
style="@style/ConstraintDefault"
app:layout_constraintTop_toBottomOf="@id/include_toolbar" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
style="@style/Fab"
app:srcCompat="@drawable/ic_add" />
</android.support.constraint.ConstraintLayout>
对于我认为约束布局是一种过分的做法,您只有一个recylcer视图,我建议您使用协调器布局。
像这样的
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="Your Context"
tools:showIn="@layout/activity_main">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
要取消设置约束布局属性,必须使用负数对其进行阴影处理:
app:layout_constraintTop_toTopOf="-1" // Upd: It's DEPRECATED! Use the method below
事实证明,将布局属性移动到style.xml
不是一个好主意。最好在那里编写样式属性(background
,textSize
,font
,等等)
更新
对于较新的约束布局版本,此方法不再有效,并引发编译时错误。正如@jeff padgett所建议的,您应该使用空引用:
app:layout_constraintTop_toTopOf="@null"
要取消设置样式中的约束集,请使用:
app:layout\u constraintop\u toTopOf=“@null”
同意,但我只提供了布局的一部分。问题是如何删除从样式中接收到的一些属性这给了我一个错误,当我使用它时,它可能曾经工作过,但现在似乎不工作了。