2017-03-13 4 views
1

Ich bin neu in Android, ich erstelle meine erste einfache App auf Android Studio, aber Einschränkungen Layout funktioniert nicht richtig auf echte Telefon oder virtuelles Telefon. Ich beabsichtige, einen Knopf in die Mitte des Layouts zu setzen, und einen Text oben auf dem Layout, aber wenn ich renne, haben beide die gleiche Position rechts oben, also kann ich keinen Text eingeben und den Knopf drücken .
Ich versuche, RelativeLayout zu verwenden, und es hat funktioniert, also vermute ich, dass das Problem von ConstraintLayout kommt. Bitte hilf mir, es zu reparieren!

Ich habe bereits "ConstraintsLayout für Android 1.0.1 oder niedriger" und "Solver für ConstraintsLayout 1.0.1 oder niedriger" installiert. In build.gradle habe kompiliert 'com.android.support.constraint: constraint-layout: 1.0.1' Ich benutze Android Studio Version 2.3. Und hier ist mein xml-Code:Constraints Layout von Android Studio funktioniert nicht richtig

<?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:context="my.android.myfirstapp.MainActivity"> 


<Button 
    android:id="@+id/btn_jump" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Jump Activity" 
    tools:layout_editor_absoluteX="128dp" 
    tools:layout_editor_absoluteY="269dp" /> 

<EditText 
    android:id="@+id/edt_Name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:ems="10" 
    android:inputType="textPersonName" 
    android:text="" 
    tools:layout_editor_absoluteX="85dp" 
    tools:layout_editor_absoluteY="62dp" /> 
</android.support.constraint.ConstraintLayout> 

Und hier ist meine einfache Anwendung bei der Ausführung:
enter image description here

Antwort

2

Ihre Einschränkungen nicht Setup richtig, wenn Sie sich nicht sicher, klicken Sie auf die Schaltfläche angezeigt in der sind Bild unten, um zu sehen, was das Problem ist .. normalerweise werden alle Layout-Probleme dort gezeigt.

Layout issue

Verwenden Sie den folgenden Code, um es um das Problem für Einschränkung behebt.

<?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:layout_editor_absoluteY="81dp" 
    tools:layout_editor_absoluteX="0dp"> 


    <Button 
     android:id="@+id/btn_jump" 
     android:layout_width="128dp" 
     android:layout_height="48dp" 
     android:text="Jump Activity" 
     tools:layout_constraintTop_creator="1" 
     tools:layout_constraintRight_creator="1" 
     tools:layout_constraintBottom_creator="1" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     tools:layout_constraintLeft_creator="1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <EditText 
     android:id="@+id/edt_Name" 
     android:layout_width="215dp" 
     android:layout_height="43dp" 
     android:ems="10" 
     android:inputType="textPersonName" 
     android:text="" 
     tools:layout_constraintTop_creator="1" 
     tools:layout_constraintRight_creator="1" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginTop="107dp" 
     tools:layout_constraintLeft_creator="1" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintHorizontal_bias="0.502" /> 
</android.support.constraint.ConstraintLayout> 

Hoffnung dieser Hilfe, wenn es funktioniert die Antwort

+3

der XML-Code wird erzeugt, indem Android Studio do markiert, und ich habe keine Warnung oder einen Fehler wie Ihr Bild sehen. Aber Ihr Code läuft perfekt, und dann habe ich festgestellt, dass einige Codezeilen es richtig funktionieren lassen: app: layout_constraintBottom_toBottomOf = "Eltern", app: layout_constraintRight_toRightOf = "Eltern", app: layout_constraintLeft_toLeftOf = "Eltern" app: layout_constraintTop_toTopOf = "Elternteil" Endlich, vielen Dank für Ihre Hilfe! (Sorry, ich weiß nicht, wie man das Codeformat in diesem Kommentar macht) –

Verwandte Themen