Vinay Nagaraj Vinay Nagaraj - 1 month ago 95
Android Question

Constraint layout chain packed usage

I'm trying to centre two textviews vertically using constraint layout chains. I know I can wrap the text layouts in a linear layout but I wanted to try out the new chain feature. When I build my project though I get an error,

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>


Anyone know what's causing this error?

Answer
app:layout_constraintLeft_toLeftOf="parent"

Maybe I'm not completely up to date, but I think the value shouldn't be "parent" - it should be a view ID (in the format of "@+id/some_id").

Give your constraint layout an id and then try using that instead of parent.

Edit: I guess I am out of date on this? Because I just read that again, and your error seems like this line:

layout_constraintBottom_toTopOf="@id/item_school_location"

is missing the + after @ - as in it should be

layout_constraintBottom_toTopOf="@+id/item_school_location"