Android 为什么我的布局会导致我的应用程序崩溃?

Android 为什么我的布局会导致我的应用程序崩溃?,android,android-layout,Android,Android Layout,为了避免布局崩溃,我需要遵守哪些规则 例如,我的布局只有4个按钮和4个文本视图。 我真的不知道为什么它会在一些设备上导致崩溃,在其他设备上它工作正常 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientat

为了避免布局崩溃,我需要遵守哪些规则

例如,我的布局只有4个按钮和4个文本视图。 我真的不知道为什么它会在一些设备上导致崩溃,在其他设备上它工作正常

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/ConnectButton"
        android:layout_width="300dp"
        android:layout_height="70dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="@string/Connect" >
    </Button>

    <Button
        android:id="@+id/DisconnectButton"
        android:layout_width="300dp"
        android:layout_height="70dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="@string/Disconnect" >
    </Button>

    <Button
        android:id="@+id/NoAlertButton"
        android:layout_width="120dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="@string/NoAlert" >
    </Button>

    <Button
        android:id="@+id/MildAlertButton"
        android:layout_width="120dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="@string/MildAlert" >
    </Button>

    <Button
        android:id="@+id/HighAlertButton"
        android:layout_width="120dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="@string/HighAlert" >
    </Button>

    <TextView
        android:id="@+id/AlertLevelSelectionLabel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/SelectAlertLevel" >
    </TextView>

    <TextView
        android:id="@+id/CurrentRSSILevelLabel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/CurrentRSSILevel" >
    </TextView>

    <TextView
        android:id="@+id/ConnectedToLabel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/ConnectToLabel" >
    </TextView>

    <TextView
        android:id="@+id/ImmediateAlert"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#ffff3333"
        android:text="@string/ImmediateAlert"
        android:textSize="42sp"
        android:textStyle="bold" >
    </TextView>

</LinearLayout>

崩溃只会在单击按钮后出现,因此它可能与它们后面出现的文本视图有关,但我不知道为什么文本视图会导致布局崩溃。
我认为这是一个布局问题,因为同一应用程序的水平布局工作正常。

你能显示你的logcat详细信息吗?我猜你的
纵向布局和
横向布局对于某些元素有不同的ID,因此崩溃…请确保你的按钮ID有效(从设置的布局中)!!K-ballo是对的。。陆地和港口有不同的布局吗?按钮ID是相同的。它们都是在上面的代码中写的,所以我猜它们是有效的名称,因为它适用于水平方向。