-4

我學習Android Studio中的第一次,我被卡住試圖將一個物理Android設備上運行的程序。我遇到的問題是我的設備上沒有任何內容(小部件,文本視圖,按鈕)出現在屏幕上。我使用的電腦有問題嗎?我可以在編輯器中看到和操作小部件,但是我創建的屏幕上的很多東西不會顯示在除藍圖外的正確位置。在設計視圖中,部件無法正確顯示?

我已經附上一切的圖像,所以你們可以去看看。我在AMD A10- 9600p Radeon R5上運行這個。 感謝您的幫助。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
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="match_parent" 
tools:ignore="MissingConstraints"> 

<TextView 
    android:text="TextView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/textView2" 
    tools:ignore="UnknownId" 
    tools:layout_editor_absoluteY="42dp" 
    android:layout_marginStart="16dp" 
    app:layout_constraintLeft_toLeftOf="@+id/constraintLayout" 
    android:layout_marginLeft="16dp" /> 

<EditText 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:inputType="textMultiLine" 
    android:ems="10" 
    android:id="@+id/editText" 
    android:layout_marginTop="16dp" 
    app:layout_constraintTop_toBottomOf="@+id/textView2" 
    android:layout_marginStart="16dp" 
    app:layout_constraintLeft_toRightOf="@+id/textView2" 
    android:layout_marginLeft="16dp" 
    tools:ignore="UnknownId" 
    android:text="Hello this is my first app and I have no clue what I'm  doing! Hopefully this all works out! I just need a bunch of words so i can create scorolling i am just typing things as fast as i can its problaly mispselled but who realy gives a hooot! just like the pokemon. this comupuete is decent but the bang for the buck is where its at. I caould make raps for fday s but its ok oops i guess i need some more word so this lovely app can scroll like a bouss hog out of the kitchen i think ill go get some ice cream soon yes great idea mr culver holla at ur boy yes" 
    app:layout_constraintBottom_toTopOf="@+id/button3" 
    android:layout_marginBottom="16dp" 
    app:layout_constraintHorizontal_bias="0.75" 
    app:layout_constraintVertical_bias="0.8" 
    android:layout_marginEnd="16dp" 
    app:layout_constraintRight_toRightOf="@+id/constraintLayout" 
    android:layout_marginRight="16dp" /> 

<Button 
    android:text="CANCEL" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/button2" 
    tools:ignore="UnknownId" 
    tools:layout_editor_absoluteY="436dp" 
    tools:layout_editor_absoluteX="268dp" /> 

<Button 
    android:text="OK" 
    android:layout_width="88dp" 
    android:layout_height="48dp" 
    android:id="@+id/button3" 
    app:layout_constraintRight_toLeftOf="@+id/button2" 
    android:layout_marginEnd="16dp" 
    android:layout_marginRight="16dp" 
    tools:ignore="UnknownId" 
    app:layout_constraintBaseline_toBaselineOf="@+id/button2" /> 
</android.support.constraint.ConstraintLayout> 

Image from Android Device

Android Studio Screenshot

+0

請發表您的佈局XML。 –

回答

0

看來,很多小部件實際上沒有限制。刪除工具:ignore =「MissingConstraints」屬性以查看缺少的工具。每個小部件至少需要約束兩個約束(一個用於垂直軸,一個用於水平軸)。

事情正確顯示在佈局編輯器只是因爲它更漂亮讓你把他們當你在設計東西的窗口小部件,即使他們沒有約束。但在設備上,這些固定位置不被使用。

+0

非常感謝!我再次創建了該項目,它工作得很好。我一定把某些方面的限制搞砸了。 –