2017-03-16 12 views
-8

Ich habe eine einfache Android-App und stürzt weiter ab, wenn ich es starte. Der Emulator sagt "Appname hört auf". Ich habe den Standardcode in der Aktivitätsklasse nicht bearbeitet. Mein Layout xml ist unten:Meine einfache Android-App stürzt ab

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 

> 
<TextView 
    android:id="@+id/lblName" 
    android:text="Name" 
    android:layout_alignParentTop="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    /> 
<EditText 
    android:id="@+id/txtName" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@id/lblName" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:inputType="text" 
    /> 
<LinearLayout 
    android:layout_alignParentLeft="true" 
    android:layout_below="@id/txtName" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 
    <Button 
    android:id="@+id/btnSubmit"  
    android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:text="Submit" 
    ></Button> 
    <Button 
    android:id="@+id/btnCancel"  
    android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:text="Cancel" 
    ></Button> 
    </LinearLayout> 
    </RelativeLayout> 
+1

post yout logcat oder Fehler, den Sie bekommen –

+0

post stacktrace atleast – Piyush

+0

Zeigen Sie uns die Log-Fehler und Aktivitätscode –

Antwort

2

Buttons innerhalb der LinearLayout das Attribut sollte android:layout_width="0dp"

+0

o k lass mich es versuchen ............................ –

+0

vielen Dank es funktioniert –

+0

Gern geschehen –

0

Ich habe Ihr Layout zu beheben, die android hinzufügen: weightSum = "1" auf Linearlayout und Breite auf den Knopf auf 0 dp

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 

<TextView 
    android:id="@+id/lblName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:text="Name" /> 

<EditText 
    android:id="@+id/txtName" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@id/lblName" 
    android:inputType="text" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@id/txtName" 
    android:orientation="horizontal" 
    android:weightSum="1"> 

    <Button 
     android:id="@+id/btnSubmit" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight=".5" 
     android:text="Submit" /> 

    <Button 
     android:id="@+id/btnCancel" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight=".5" 
     android:text="Cancel" /> 
</LinearLayout> 

Veröffentlichen Sie Ihre Java-Code für diese Aktivität auch :)