当我将父布局从线性更改为框架或相对时,它会给我错误

时间:2013-08-24 06:00:21

标签: android android-layout android-xml

在我以前的xml代码中,我的应用程序运行正常:

     <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" >

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="82dp" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/button1"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="Send" />

          </RelativeLayout>

        <ListView
     android:id="@android:id/list"
     android:layout_width="match_parent"
     android:layout_height="380dp" />


     </LinearLayout>

现在当我更改我的xml时,现在当我将相对布局或框架布局作为父级时,我的应用程序给出了错误“不幸的是它已停止”,我的新xml是:

  <?xml version="1.0" encoding="utf-8"?>
   <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >

      <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="86dp"
    android:layout_gravity="bottom" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="Send" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/button1"
        android:ems="10" />

  </RelativeLayout>

  <ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="372dp" >
  </ListView>

        </FrameLayout>

logcat的:

  

08-24 19:08:24.050:E / AndroidRuntime(674):at   android.app.FragmentManagerImpl.moveToState(FragmentManager.java:809)   08-24 19:08:24.050:E / AndroidRuntime(674):at   android.app.FragmentManagerImpl.moveToState(FragmentManager.java:998)   08-24 19:08:24.050:E / AndroidRuntime(674):at   android.app.BackStackRecord.run(BackStackRecord.java:622)08-24   19:08:24.050:E / AndroidRuntime(674):at   android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1330)   08-24 19:08:24.050:E / AndroidRuntime(674):at   android.app.Activity.performStart(Activity.java:4474)08-24   19:08:24.050:E / AndroidRuntime(674):at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1928)   08-24 19:08:24.050:E / AndroidRuntime(674):... 11 more

2 个答案:

答案 0 :(得分:1)

更改ListView ID,如果扩展ListActivity必须指定关键字android。

 <ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="372dp" >
</ListView>

答案 1 :(得分:0)

对不起Ameer Humza,但我在执行你的xmls时没有遇到这样的错误。

我认为你应该先尝试清理你的项目: 项目&gt;干净。

重新启动Eclipse。

你日食的版本是什么?