2017-07-21 1 views
0

Hallo, habe ich ein Problem: I Android mit Android Studio bin nähert, aber ich habe festgestellt, Probleme mit XML, Ich versuche, ein wenig Rechner zu tun:Entwurf mit Android Studio

In der IDE ich alles perfekt sehen, aber wenn ich eine Simulation starten ... enter image description here

So ... können Sie mir helfen? Es gibt eine Möglichkeit für Anker Tasten und Texte?

Vielen Dank im Voraus und Entschuldigung für mein schlechtes schlechtes Englisch.

+1

Bitte geben Sie Ihren XML-Code ein –

+0

Verwenden Sie RelativeLayout! –

+0

Warum verwenden Sie die Einschränkungen nicht, wenn Sie constraintLayout bereits verwenden? – Vacutainer

Antwort

0

Ihre xml kann so geändert werden, es funktioniert nur gleiche xml Unterschied. Es passiert wegen <android.support.constraint.ConstraintLayout>, Ihr Code wurde von mir geändert unten überprüfen.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
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="lorenzo.calculator.Calcolatrice" 
android:orientation="vertical"> 

<TableRow 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <EditText 
     android:id="@+id/editText" 
     android:layout_width="337dp" 
     android:layout_height="40dp" 
     android:ems="10" 
     android:inputType="textPersonName" 
     android:text="Numero 1" /> 
</TableRow> 

<TableRow 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <EditText 
     android:id="@+id/editText2" 
     android:layout_width="337dp" 
     android:layout_height="42dp" 
     android:ems="10" 
     android:inputType="textPersonName" 
     android:text="Numero 2" /> 

</TableRow> 

<TableRow 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum="1"> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="88dp" 
     android:layout_height="49dp" 
     android:text="-" 
     android:layout_weight="0.25"/> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="88dp" 
     android:layout_height="49dp" 
     android:text="/" 
     android:layout_weight="0.25"/> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="88dp" 
     android:layout_height="49dp" 
     android:text="+" 
     android:layout_weight="0.25"/> 

    <Button 
     android:id="@+id/button4" 
     android:layout_width="88dp" 
     android:layout_height="49dp" 
     android:text="*" 
     android:layout_weight="0.25"/> 
</TableRow> 

<TextView 
    android:id="@+id/textView" 
    android:layout_width="348dp" 
    android:layout_height="316dp" 
    android:textColor="@android:color/background_dark" 
    android:textSize="36sp" /> 

</LinearLayout> 
+0

Wo kann ich es ändern? –

+0

Ich habe einige Änderungen in Ihrem Code vorgenommen, überprüfen Sie es bitte oben. –

0

XML-Code:

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

<Button 
    android:id="@+id/button4" 
    android:layout_width="56dp" 
    android:layout_height="49dp" 
    android:text="*" 
    tools:layout_editor_absoluteX="288dp" 
    tools:layout_editor_absoluteY="137dp" /> 

<Button 
    android:id="@+id/button3" 
    android:layout_width="56dp" 
    android:layout_height="49dp" 
    android:text="+" 
    tools:layout_editor_absoluteX="16dp" 
    tools:layout_editor_absoluteY="137dp" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="56dp" 
    android:layout_height="49dp" 
    android:text="/" 
    tools:layout_editor_absoluteX="198dp" 
    tools:layout_editor_absoluteY="137dp" /> 

<EditText 
    android:id="@+id/editText" 
    android:layout_width="337dp" 
    android:layout_height="40dp" 
    android:ems="10" 
    android:inputType="textPersonName" 
    android:text="Numero 1" 
    tools:layout_editor_absoluteX="12dp" 
    tools:layout_editor_absoluteY="16dp" /> 

<EditText 
    android:id="@+id/editText2" 
    android:layout_width="337dp" 
    android:layout_height="42dp" 
    android:ems="10" 
    android:inputType="textPersonName" 
    android:text="Numero 2" 
    tools:layout_editor_absoluteX="12dp" 
    tools:layout_editor_absoluteY="74dp" /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="56dp" 
    android:layout_height="49dp" 
    android:text="-" 
    tools:layout_editor_absoluteX="106dp" 
    tools:layout_editor_absoluteY="137dp" /> 

<TextView 
    android:id="@+id/textView" 
    android:layout_width="348dp" 
    android:layout_height="316dp" 
    android:textColor="@android:color/background_dark" 
    android:textSize="36sp" 
    tools:layout_editor_absoluteX="5dp" 
    tools:layout_editor_absoluteY="193dp" /> 

+0

Bitte bearbeiten Sie Ihre Frage! nicht beantworten :) –

0

Um eine Ansicht der Position in ConstraintLayout definieren Sie mindestens eine horizontale und eine vertikale Einschränkung für die Ansicht hinzufügen. (Documentation of ConstraintLayout)

Da Sie eine einfache Ansicht implementieren werde ich mit vorschlagen LinearLayout ist der beste und einfachste Ansatz für diese Aufgabe.

Versuchen Sie den folgenden Code.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
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" 
android:orientation="vertical" 
tools:layout_editor_absoluteY="81dp" 
tools:layout_editor_absoluteX="0dp"> 



<EditText 
    android:id="@+id/editText" 
    android:layout_width="337dp" 
    android:layout_height="40dp" 
    android:ems="10" 
    android:inputType="textPersonName" 
    android:text="Numero 1" 
    tools:layout_editor_absoluteX="12dp" 
    tools:layout_editor_absoluteY="16dp" /> 

<EditText 
    android:id="@+id/editText2" 
    android:layout_width="337dp" 
    android:layout_height="42dp" 
    android:ems="10" 
    android:inputType="textPersonName" 
    android:text="Numero 2" 
    tools:layout_editor_absoluteX="12dp" 
    tools:layout_editor_absoluteY="74dp" /> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_marginTop="10dp" 

    > 
    <Button 
     android:id="@+id/button4" 
     android:layout_width="56dp" 
     android:layout_height="49dp" 
     android:text="*" 
     tools:layout_editor_absoluteX="288dp" 
     tools:layout_editor_absoluteY="137dp" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="56dp" 
     android:layout_height="49dp" 
     android:text="+" 
     tools:layout_editor_absoluteX="16dp" 
     tools:layout_editor_absoluteY="137dp" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="56dp" 
     android:layout_height="49dp" 
     android:text="/" 
     tools:layout_editor_absoluteX="198dp" 
     tools:layout_editor_absoluteY="137dp" /> 
    <Button 
     android:id="@+id/button" 
     android:layout_width="56dp" 
     android:layout_height="49dp" 
     android:text="-" 
     tools:layout_editor_absoluteX="106dp" 
     tools:layout_editor_absoluteY="137dp" /> 

</LinearLayout> 



<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@android:color/background_dark" 
    android:textSize="36sp" 
    tools:layout_editor_absoluteX="5dp" 
    tools:layout_editor_absoluteY="193dp" /> 

</LinearLayout>