0

私のアプリには、2つのボタンと、ListFragmentが読み込まれるスペースがあります。ボタンがレイアウトの一番上にあるように定義されている場合、アプリは希望どおりに実行されます。

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0px"
        android:orientation="horizontal" >
        <Button
            android:id="@+id/displayfragment1"
            android:layout_height="match_parent"
            android:layout_width="wrap_content"
            android:text="@string/button_fragment1" />
        <Button
            android:id="@+id/displayfragment2"
            android:layout_height="match_parent"
            android:layout_width="wrap_content"
            android:text="@string/button_fragment2" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/myfragment"
        android:layout_width="match_parent"
        android:layout_weight="5"
        android:layout_height="0px" />
</LinearLayout>

ただし、以下のようにフラグメントレイアウトをボタンの上に移動すると、起動時にアプリがクラッシュします。

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

    <LinearLayout
        android:id="@+id/myfragment"
        android:layout_width="match_parent"
        android:layout_weight="5"
        android:layout_height="0px" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0px"
        android:orientation="horizontal" >
        <Button
            android:id="@+id/displayfragment1"
            android:layout_height="match_parent"
            android:layout_width="wrap_content"
            android:text="@string/button_fragment1" />
        <Button
            android:id="@+id/displayfragment2"
            android:layout_height="match_parent"
            android:layout_width="wrap_content"
            android:text="@string/button_fragment2" />
    </LinearLayout>       

</LinearLayout>

これは私がこのクラッシュを引き起こすために行っている唯一の変更であり、これが問題であるに違いないと思いますか?

4

1 に答える 1

2

R関係するもの(特にレイアウトのもの)を変更した後は、必ずプロジェクトをクリーンアップすることを忘れないでください([プロジェクト]-> [クリーン] )。Eclipseは、変更Rを反映するために変更を「忘れる」(または、ここで問題と思われるように誤って変更する)場合があり、奇妙な問題が発生します。

于 2013-01-06T21:22:44.870 に答える