2016-09-30 5 views
1

私は制約レイアウトチェーンを使用して2つのテキストビューを垂直方向に中央に配置しようとしています。私はリニアレイアウトでテキストレイアウトをラップすることができますが、私は新しいチェーン機能を試してみたかったのです。私はエラーを取得するのに、私は私のプロジェクトをビルドすると、Error:(28, 50) No resource found that matches the given name (at 'layout_constraintBottom_toTopOf' with value '@id/item_school_location').制約レイアウトチェーンパックされた使用

<?xml version="1.0" encoding="utf-8"?> 
<layout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="72dp"> 

     <ImageView 
      android:id="@+id/item_school_logo" 
      android:layout_width="48dp" 
      android:layout_height="48dp" 
      android:layout_marginStart="16dp" 
      android:contentDescription="@string/item_school_logo_description" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toTopOf="parent" 
      app:layout_constraintVertical_bias="0.5" /> 

     <TextView 
      android:id="@+id/item_school_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="16dp" 
      android:layout_marginStart="72dp" 
      android:maxLines="1" 
      android:textAppearance="@style/TextAppearance.AppCompat.Light.SearchResult.Subtitle" 
      app:layout_constraintBottom_toTopOf="@id/item_school_location" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toTopOf="parent" 
      app:layout_constraintVertical_bias="0.5" 
      app:layout_constraintVertical_chainPacked="true" /> 

     <TextView 
      android:id="@+id/item_school_location" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="16dp" 
      android:layout_marginStart="72dp" 
      android:maxLines="1" 
      android:textAppearance="@style/TextAppearance.AppCompat.Small" 
      android:textSize="16sp" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toBottomOf="@id/item_school_name" /> 
    </android.support.constraint.ConstraintLayout> 
</layout> 

誰もがこのエラーを引き起こしているか知っていますか?

答えて

5
app:layout_constraintLeft_toLeftOf="parent" 

は、たぶん私は完全に最新ではないんだけど、私は値が「親」であるべきではないと思う - それは(「@ + ID/some_id」の形式で)ビューのIDでなければなりません。

あなたの制約レイアウトにidを与えてから、代わりにそれを使ってみてください。

を編集してください:これは古くなったと思いますか?私は再びそれを読んで、あなたのエラーは、この行のように思えるので:

layout_constraintBottom_toTopOf="@id/item_school_location" 

は、@の後に+が不足している - それは

layout_constraintBottom_toTopOf="@+id/item_school_location" 
+0

ほら!私も同様の問題がありました。私はこれがうまくいくとは思っていませんでしたが、そうしました。私は最初のIDへの参照(上から)が+記号を持つべきだと思います。 – amram99

+0

@ amram99 - 私が知る限り、レイアウトファイル内のIDへのすべての参照には+が前に付いていなければなりません。試してみてください。あなたの参照がIDの2番目の出現であっても、+ –

+1

がなくても正しく動作しません。実際に+はあなたが新しいIDを割り当てていることを示しています。通常はRelativeLayoutのように+を付けずにIDを参照しますが、同じIDを複数回割り当ててもAndroidは寛容です。この答えはhttp://stackoverflow.com/a/5731533/389643ですが、Android要素の順序を使用してzオーダーを定義します。要素の定義の上にあるIDを参照する必要があります。また、コンパイラーの問題が発生することもあります。 – amram99

1

あるべきのように私は

を考えます指定された名前と一致するリソースが見つかりません

エラーは、参照していることが原因ですそれを参照する要素(item_school_name)の後に宣言された要素のID(item_school_location)。この場合

あなたは別のids.xmlファイルにあなたの関連要素のidを宣言した場合、それが役立つだろうが(このチェック:https://stackoverflow.com/a/12247971)を

関連する問題