Mik*_*ike 8 android android-layout android-constraintlayout
我想弄清楚为什么这不起作用.我只添加了两个<include>
部分,ConstraintLayout
并且布局不遵循我设置的任何约束.我想开始迁移到使用ConstraintLayout
作为我去到布局,但像这样的事情不断推动我回RelativeLayout
并LinearLayout
.
这是顶级布局文件(ConstraintLayout),显示了一些不起作用的约束:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<include
android:id="@+id/includeButton"
layout="@layout/include_button_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<include
android:id="@+id/includeText"
layout="@layout/include_text_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
</android.support.constraint.ConstraintLayout
Run Code Online (Sandbox Code Playgroud)
这是第一个包含的布局(include_button_panel):
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="@+id/include_button_panel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Touch me!" />
</merge>
Run Code Online (Sandbox Code Playgroud)
这是第二个包含的布局(include_text_panel):
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/include_text_panel_text"
android:layout_width="wrap_content"
android:background="#7986cb"
android:layout_height="wrap_content"
android:text="This is the text panel"
android:textColor="@android:color/black"
android:textSize="18sp" />
</merge>
Run Code Online (Sandbox Code Playgroud)
<merge>
从两个包含的布局中删除标记.
在<include>
标记上指定属性时,系统会将这些属性应用于包含布局的根视图.该<merge>
标签是为了让你在你的布局多个视图的特殊元素,而不具有根部视图.因此,当您包含的布局使用<merge>
标记时,所有约束都会被抛弃.幸运的是,两个包含的布局在合并中只有一个视图,因此您可以完全删除合并.
尝试此操作<merge>
从两个包含的布局中删除标签
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<include
android:id="@+id/includeButton"
layout="@layout/include_button_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<include
android:id="@+id/includeText"
layout="@layout/include_text_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2826 次 |
最近记录: |