【问题标题】:When I changed my parent layout from linear to frame or relative it gives me error当我将父布局从线性更改为框架或相对时,它给了我错误
【发布时间】:2013-08-24 06:00:21
【问题描述】:

在我之前的 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): 在 android.app.FragmentManagerImpl.moveToState(FragmentManager.java:809) 08-24 19:08:24.050: E/AndroidRuntime(674): 在 android.app.FragmentManagerImpl.moveToState(FragmentManager.java:998) 08-24 19:08:24.050: E/AndroidRuntime(674): 在 android.app.BackStackRecord.run(BackStackRecord.java:622) 08-24 19:08:24.050:E/AndroidRuntime(674):在 android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1330) 08-24 19:08:24.050: E/AndroidRuntime(674): 在 android.app.Activity.performStart(Activity.java:4474) 08-24 19:08:24.050:E/AndroidRuntime(674):在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1928) 08-24 19:08:24.050: E/AndroidRuntime(674): ... 11 更多

【问题讨论】:

  • 你手动改了吗?
  • 你有没有先阅读框架布局?点击链接developer.android.com/reference/android/widget/FrameLayout.html我想知道您在这里使用框架布局的要求?也发布日志跟踪。
  • 发布你的 logcat 错误。
  • 您的布局在我的模拟器中运行良好。可能是您在 Java 类中做错了什么。
  • 我已经用完整的 log cat 错误详细信息编辑了我的问题,请检查,

标签: android android-layout android-xml


【解决方案1】:

改变你的ListView id,如果你扩展ListActivity必须指定关键字android。

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

【讨论】:

  • 您说得对,但是当我更改我的 id xml 时出现错误,然后我的项目包含错误! @rahul
  • ArrayAdapter 适配器 = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, values); setListAdapter(适配器);如果你从中得到什么,请检查我的适配器?
【解决方案2】:

抱歉,Ameer Humza,但我在执行您的两个 xmls 时没有收到这样的错误。

我认为您应该先尝试清理您的项目: 项目 > 清理。

重新启动 Eclipse。

你的eclipse是什么版本的?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-13
    • 2019-10-15
    • 2017-10-01
    相关资源
    最近更新 更多