anko icon indicating copy to clipboard operation
anko copied to clipboard

anko layout : generate id by default (especially for constraintLayout)

Open benjaminledet opened this issue 7 years ago • 9 comments

ConstraintLayout needs its views to have an id to constrain them. I think it's useless to define ids in xml files just for that so I have to write for each view "id = View.generateViewId ()" Why not put this option for all views by default so you do not have to write it every time because anyway, setting an id manually will override this default id.

    ConstraintLayout {

            icon = imageView{
                id = View.generateViewId()
            }.lparams {
                width = dip(40)
                height = dip(40)
            }

            label = textView {
                id = View.generateViewId()
                textSize = 18f
                typeface = Typeface.DEFAULT_BOLD
            }

            spendedLabel = textView {
                id = View.generateViewId()
                textResource = R.string.spended
            }

            spended = textView {
                id = View.generateViewId()
                textColorResource = R.color.dark_red
            }

            budgetLabel = textView {
                id = View.generateViewId()
                textResource = R.string.budget
            }

            budget = textView {
                id = View.generateViewId()
                textColorResource = R.color.primaryColor
            }

            remainingLabel = textView {
                id = View.generateViewId()
                textResource = R.string.remaining
            }

            remaining = textView {
                id = View.generateViewId()
                textColorResource = R.color.teal
            }

            progress = horizontalProgressBar {
                id = View.generateViewId()
            }.lparams { width = matchParent }

            applyConstraintSet {
            ...

benjaminledet avatar Jan 03 '18 11:01 benjaminledet

+1 The converted to Anko example for Google's ConstraintLayout Codelab only works because of the preexisting IDs defined in the activity_main_done.xml layout file, which is confusing. The Anko code should work even if we delete all of the legacy layout XML files.

naveedhasan avatar Jan 23 '18 03:01 naveedhasan

MainActivity.kt.txt - working update of MainActivity.kt that does not use data from layout XML files.

naveedhasan avatar Jan 23 '18 16:01 naveedhasan

+1

seaskyways avatar Apr 28 '18 15:04 seaskyways

+1

mkubasz avatar Jul 11 '18 21:07 mkubasz

+1

ahmafi avatar Sep 10 '18 17:09 ahmafi

+1

kiratheone avatar Oct 30 '18 03:10 kiratheone

+1 need this a lot

u201701 avatar Mar 13 '19 10:03 u201701

+1 must have

Rasalexman avatar Mar 13 '19 12:03 Rasalexman

+1 It seems like a good idea. Is there any downside to doing this?

eitzend avatar Mar 22 '19 03:03 eitzend