Jan Slominski Jan Slominski - 1 month ago 22
Android Question

Problems with Layout Editor in Android Studio 2.2.1 using Constraint Layout

I'm having trouble with Android Studio's Layout Editor after updating to Android Studio 2.2.1 (from stable channel). The editor is sometimes hiding "Constraint Layout" controls from the UI, as shown on the screenshots below:

Screenshot

I'm using Constraint Layout alpha 9 and Data Binding hence the layout is wrapped in "layout" tag. Here is the code for example layout:

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

<data>
<variable
name="viewModel"
type="my.package.name.DashboardViewModel"/>
</data>

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.constraint.ConstraintLayout>
</layout>


The controls are disappearing and appearing when I add/remove elements from the layout. Is this a bug in the new Android Studio or Constraint Layout? Or am I doing something wrong?

Answer

Let's call that a bug :)

(I just filed it here: https://code.google.com/p/android/issues/detail?id=224973)

What's happening is that we only show the controls that can apply to the current selection, or the root if things aren't selected. Because of the layout tag, the root isn't a ConstraintLayout, so we don't show the controls until you select an element. This is an issue you will encounter too if you embed a CL inside another layout, but at least in the case of databinding we probably should behave as if root was the CL element.

Thanks, we'll try to fix this asap.