我正在编写一个应用程序,我需要为不同的屏幕方向编写不同的布局。
让我解释一下我的用例给某人指点。我有什么:
我的项目中的activity
在Fragment
纵向模式下有3 ViewPager
个,与手机上的横向模式和平板电脑上的纵向相同。这部分工作正常,所有功能都按照要求编写。
现在,我们需要在平板电脑上编写横向模式,这将在一个布局中显示来自Fragment
的{{1}}中的所有3个布局。所以,我所做的是
layout / activity_main.xml - ViewPager
并使用ViewPager
加载Fragment
,它适用于手机(端口,陆地)和平板电脑(端口)
layout-sw600dp-land / activity_main.xml - 有一个FragmentPagerAdapter
,我在FrameLayout
添加Fragment
,首先检查viewPager == null
,即内容视图设置为来自activity_main.xml
layout-sw600dp-land
醇>
但这导致跟随错误
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sf.quid/com.sf.quid.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030024
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3738)
at android.app.ActivityThread.access$900(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030024
at android.content.res.Resources.getValue(Resources.java:1123)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2309)
at android.content.res.Resources.getLayout(Resources.java:939)
at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.sf.quid.fragment.MainFragment.onCreateView(MainFragment.java:23)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1097)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1895)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:566)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5241)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3738)
at android.app.ActivityThread.access$900(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
而且,当
时,它正在Nexus 7标签上发生请帮忙。
谢谢。