2016-06-14 77 views
47

我收到以下錯誤,我正在使用Android studio 2.2 Preview 3.我搜索了Google,但找不到任何資源。此視圖不受限制

Error: This view is not constrained, it only has design time positions, so it will jump to (0,0) unless you add constraints 

enter image description here

<TextView 
     android:layout_width="384dp" 
     android:layout_height="207dp" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="@string/calc_default_display" 
     android:id="@+id/textView" 
     android:background="#ffffff" 
     android:layout_margin="0dp" 
     android:gravity="bottom|end" 
     android:textSize="70sp" 
     android:nestedScrollingEnabled="false" 
     android:maxLines="2" 
     android:maxLength="17" 
     tools:layout_editor_absoluteX="0dp" 
     tools:layout_editor_absoluteY="0dp" /> 

回答

3

你需要通過點擊工具欄上的魔術棒按鈕來手動給出一個值來約束自動使用新的佈局編輯器缺少約束可以添加時設計預覽的菜單。

115

快速解決此問題,使用這個非常有用的快捷方式在Android的工作室:

右鍵單擊窗口小部件功能於問題>約束佈局>推斷約束:

enter image description here

此後,您可以按照此處所述調整約束:https://stackoverflow.com/a/37960888/5556250

更新

這不適用於Android Studio v3及更高版本。按照@purpleladydragons's comment

「約束佈局」不在下拉菜單中。使用設計預覽上方工具欄菜單中的魔術棒圖標;有「Infer Constraints」按鈕。

+2

非常感謝您的解決方案,我是一個絕對的初學者,我不知道什麼是錯的部件位置 –

+1

的最佳解決方案,雖然我希望Android Studio只會存儲起跑位置,而不是運行時間位置。更好的問題是谷歌爲什麼只在運行期間存儲位置是個好主意?這是讓開發者點擊推斷位置的不必要的步驟。 – Antony

+0

非常感謝!非常有幫助 – Paul

6

右鍵單擊,然後在其中得到了錯誤組件設計部分,按照下列步驟操作:

  • [爲前。如果發生在純文本錯誤]

[1]

純文本約束佈局「,由此推斷約束:

終於錯誤已經

8

你可以試試這個: 1。確保你已經添加了:compile'c​​om.android.support:design:25.3.1'(也許你還應該加上編譯 'com.android.support.constraint:約束的佈局:1.0.2') 2. enter image description here

3.click的推斷約束,希望它可以幫助你。

21

Solution

只需點擊此,它都將迎刃而解