Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constraint layout Layout Crashing : All Children of constraint layout should have ids to use constraint set

Tags:

After updating to com.android.support.constraint:constraint-layout:1.1.0

The constraint layout crashes saying:

All children of constraint layout should have ids to use constraint set

I have set ids to all views even then it's crashing.

java.lang.RuntimeException: All children of ConstraintLayout must have ids to use ConstraintSet at android.support.constraint.ConstraintSet.clone(ConstraintSet.java:687) at com.zoho.notebook.views.SettingsViewNavBar.showNoteSettingsView(SettingsViewNavBar.java:594) at com.zoho.notebook.views.SettingsViewNavBar.onClick(SettingsViewNavBar.java:303) 
like image 376
Saikrishna Rajaraman Avatar asked May 25 '18 10:05

Saikrishna Rajaraman


People also ask

What is a Constraint layout?

A ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way. Note: ConstraintLayout is available as a support library that you can use on Android systems starting with API level 9 (Gingerbread). As such, we are planning on enriching its API and capabilities over time.

Why use Constraint layout?

ConstraintLayout provides you the ability to completely design your UI with the drag and drop feature provided by the Android Studio design editor. It helps to improve the UI performance over other layouts. With the help of ConstraintLayout, we can control the group of widgets through a single line of code.

How to create Constraint layout in Android Studio?

Create a new layout To start a new constraint layout file, follow these steps: In the Project window, click the module folder and then select File > New > XML > Layout XML. Enter a name for the layout file and enter "androidx.constraintlayout.widget.ConstraintLayout" for the Root Tag. Click Finish.

Which of the following Constraint types expands a view only as much as needed to fit its contents?

This is the default behavior. wrap: Expands the view only as much as needed to fit its contents, but still allows the view to be smaller than that if the constraints require it.


1 Answers

I had the same bug in my code. I had ids for all the views in xml, but I was manually adding a view to the constraint layout(a Tooltip view) with

constraintParent.addView(childView) 

and while the dynamically added view is still on the parent if the constraint layout is redrawn (app goes to bg and resumed) this exception was getting triggered.

I fixed it by generating a view id for the dynamic view like this

CustomViewChildView childView = new CustomViewChildView() childView.setId(View.generateViewId());  

and then adding it to the constraint layout.

like image 150
hushed_voice Avatar answered Sep 24 '22 01:09

hushed_voice