6

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> 

也恰好外面滾動視圖。

+1

後的XML代碼在這裏,您 –

+0

並不真正需要明確的代碼行,它發生在任何地方.. – PadySo

+0

點擊屬性的DP值。並檢查維度。 –

回答

1

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


我覺得這背後的原因是,ConstraintLayout作爲一個所見即所得的佈局必然意味着要編輯/操作僅在可視化編輯器。

因此,在您的dimens.xml中保留對維度的引用意味着只要您改變某些內容,移動一些元素,這些元素就不再相關,因此被替換爲「實際當前值」。

另外,如docs提到:

該工具提供的所有利潤8DP的因素,幫助你的意見對準材料設計的8DP方格網的建議。