的Android ConstraintLayout @dimens替换硬编码值
问题描述:
Heyho队友,的Android ConstraintLayout @dimens替换硬编码值
目前我正在学习Android Studio中的新布局编辑器新ConstraintLayout。
顺便说一句,我讨厌它。
但我得到的问题,如果我想指定与@dimen一个layout_height,它得到取代与DP值来代替。
其他人有这个问题吗?
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>
也恰好外面滚动视图。
答
Turns out this is a bug and will be fixed in Android Studio 2.3.
我觉得这背后的原因是,ConstraintLayout作为一个所见即所得的布局必然意味着要编辑/操作仅在可视化编辑器。
因此,在您的dimens.xml中保留对维度的引用意味着只要您改变某些内容,移动一些元素,这些元素就不再相关,因此被替换为“实际当前值”。
另外,如docs提到:
该工具提供的所有利润8DP的因素,帮助你的意见对准材料设计的8DP方格网的建议。
后的XML代码在这里,您 –
并不真正需要明确的代码行,它发生在任何地方.. – PadySo
点击属性的DP值。并检查维度。 –