Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ConstraintLayout @dimens replaced with hardcoded values

Heyho mates,

currently I am learning the new layout editor of Android Studio with the new ConstraintLayout.

By the way, I hate it.

But I got the issue, that if I want to specify a layout_height with @dimen, it gets replaced with a dp value instead.

Someone else got this issue?

Android Studio version 2.2.2 & 2.2.3 same issue.

Newest gradle version.

Thanks in advance guys!

Edit :

Code example :

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="@dimen/imageViewHeight"
            app:srcCompat="@drawable/accept"
            android:id="@+id/imageView"
            android:layout_marginStart="16dp"
            app:layout_constraintLeft_toLeftOf="parent"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            app:layout_constraintTop_toTopOf="parent" />
    </android.support.constraint.ConstraintLayout>

</ScrollView>

Also happens outside scrollview.

like image 636
PadySo Avatar asked Dec 07 '16 12:12

PadySo


1 Answers

Turns out this is a bug and will be fixed in Android Studio 2.3.


I think the reason behind this is, that ConstraintLayout as a WYSIWYG layout is inevitably meant to be edited/manipulated in the visual editor only.

Therefore keeping references to dimens in your dimens.xml would mean that as soon as you change something, move some elements around, these would not be relevant anymore and are hence replaced with "actual current values".

Also as mentioned in the docs:

All margins offered by the tool are factors of 8dp to help your views align to Material Design's 8dp square grid recommendations.

like image 189
whlk Avatar answered Oct 23 '22 06:10

whlk