Android ConstraintLayout @dimens replaced with hardcoded values

女生的网名这么多〃 提交于 2019-12-10 13:19:32

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/41018039/android-constraintlayout-dimens-replaced-with-hardcoded-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!