2017-09-19 13 views
0

これはなぜ機能しないのか理解しようとしています。私はConstraintLayoutに2つの<include>セクションを追加していますが、レイアウトは私が設定した制約に従っていません。私はConstraintLayoutのマイグレーションに移行しようとしていますが、このようなことは私をRelativeLayoutLinearLayoutに押し戻し続けています。ここConstraintLayout使用上の問題<include>

が動作していない制約の一部を示す、トップレベル・レイアウト・ファイル(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 

を最初含まれるレイアウト(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> 

ここに2番目に含まれるレイアウト(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> 

答えて

3

はあなたの付属レイアウトの両方から<merge>タグを削除し、これはあなたの付属レイアウトの両方から<merge>タグを削除してみてください。

<include>タグの属性を指定すると、システムはそれらの属性を含まれているレイアウトのルートビューに適用します。 <merge>タグは、のレイアウトで複数のビューを持つことを可能にする特別な要素です。はルートビューを持っていません。含まれているレイアウトで<merge>タグが使用されていると、すべての制約が破棄されます。幸いにも、あなたの含まれているレイアウトの両方は、マージ内に1つのビューしか持っていないので、マージを完全に削除することができます。

1

<?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 
関連する問題