Android ConstraintLayout @dimens替换为硬编码值 [英] Android ConstraintLayout @dimens replaced with hardcoded values

查看:183
本文介绍了Android ConstraintLayout @dimens替换为硬编码值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Heyho队友,

目前,我正在使用新的 ConstraintLayout 学习Android Studio的新布局编辑器.

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

顺便说一句,我讨厌它.

但是我遇到了一个问题,如果我想用 @dimen 指定 layout_height ,则会用替换 dp 值.

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版本2.2.2及更高版本2.2.3相同的问题.

最新的gradle版本.

先谢谢大家!

代码示例:

<?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>

也发生在滚动视图之外.

推荐答案

结果证明这是一个错误,将在Android Studio 2.3中修复.

我认为其背后的原因是,ConstraintLayout作为WYSIWYG布局不可避免地只能在视觉编辑器中进行编辑/操作.

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.

因此,在dimens.xml中保留对dimens的引用将意味着,一旦您进行了一些更改,移动了一些元素,这些元素将不再相关,因此将其替换为实际当前值".

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

也如 docs :

该工具提供的所有边距都是8dp的因数,以帮助您使视图与Material Design的8dp方格建议保持一致.

这篇关于Android ConstraintLayout @dimens替换为硬编码值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆