从纵向切换到横向两种不同的视图

时间:2012-03-02 11:26:23

标签: android listview galleryview landscape-portrait

我正在处理应用程序,我希望ListView在纵向模式下使用图像,GalleryView在横向模式下使用相同的图像我在res / layout-land / main.xml(Landscape)和普通res / layout / main.xml中创建了文件夹(肖像)但我得到了例外

03-02 11:21:06.420: E/AndroidRuntime(775): FATAL EXCEPTION: main
03-02 11:21:06.420: E/AndroidRuntime(775): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.landscape/com.landscape.ListAvtivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.os.Looper.loop(Looper.java:130)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ActivityThread.main(ActivityThread.java:3683)
03-02 11:21:06.420: E/AndroidRuntime(775):  at java.lang.reflect.Method.invokeNative(Native Method)
03-02 11:21:06.420: E/AndroidRuntime(775):  at java.lang.reflect.Method.invoke(Method.java:507)
03-02 11:21:06.420: E/AndroidRuntime(775):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-02 11:21:06.420: E/AndroidRuntime(775):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-02 11:21:06.420: E/AndroidRuntime(775):  at dalvik.system.NativeStart.main(Native Method)
03-02 11:21:06.420: E/AndroidRuntime(775): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ListActivity.onContentChanged(ListActivity.java:243)
03-02 11:21:06.420: E/AndroidRuntime(775):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.Activity.setContentView(Activity.java:1657)
03-02 11:21:06.420: E/AndroidRuntime(775):  at com.landscape.ListAvtivity.onCreate(ListAvtivity.java:43)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-02 11:21:06.420: E/AndroidRuntime(775):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-02 11:21:06.420: E/AndroidRuntime(775):  ... 11 more

当我从layout-land中删除main.xml时,应用程序正常工作并且只显示ListView。

1 个答案:

答案 0 :(得分:2)

在你的问题中添加layout-land中的main.xml。

layout-land / main.xml中的ListView看起来不包含android:id =“@ android:id / list”

修改

活动不应仅展开ListActivity,而应仅展开Activity,因为它会在内容视图中搜索ID为@android:id/list的列表视图。

您必须手动使用ListView