gpt4 book ai didi

Android ConstraintLayout @dimens 替换为硬编码值

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:36:31 24 4
gpt4 key购买 nike

嘿嘿 friend 们,

目前我正在学习 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>

也发生在 ScrollView 之外。

最佳答案

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


我认为这背后的原因是,作为所见即所得布局的 ConstraintLayout 不可避免地意味着只能在可视化编辑器中进行编辑/操作。

因此,在您的 dimens.xml 中保留对 dimens 的引用将意味着一旦您更改某些内容、移动一些元素,这些元素将不再相关,因此将被“实际当前值”取代。

也如docs中所述:

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

关于Android ConstraintLayout @dimens 替换为硬编码值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41018039/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com