Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Kotlin - How to extend ConstraintLayout?

I'd like my ConstaintLayout to carry extra additional properties, but I have trouble extending it. More precisely I have trouble putting correct constructor into

class myCL(): ConstraintLayout(???) {
}
like image 864
Destabilizator Avatar asked May 31 '18 20:05

Destabilizator


People also ask

Is ConstraintLayout a ViewGroup?

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).

Can we use linear layout in ConstraintLayout?

You can create linear layouts now with ConstraintLayout by constraining the sides of each element with each other. The quick way of creating these layouts is to select all the views together and right click to center horizontally or vertically.

Why do we prefer constraint ConstraintLayout in Android?

Constraint Layout simplifies creating complex layouts in Android by making it possible to build most of your UI using only the visual editor in Android Studio. Constraint Layout comes with some powerful tools with the help of which you can define complex layouts without having deep nesting.

How do you use chain in ConstraintLayout?

Creating a chain is really easy, we can click and drag to select views or press ctrl and select views from Component Tree. And then right click on selected views in Editor Or Component Tree to apply constraints. You can see that in action in following screen records.


1 Answers

To make sure you don't get any quirks in behavior, you should implement it like this.

class myCL: ConstraintLayout {
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?,
                @AttrRes defStyleAttr: Int) : super(context, attrs, defStyleAttr)
}
like image 140
EpicPandaForce Avatar answered Sep 29 '22 05:09

EpicPandaForce