在我的应用中,我使用的是View Pager和Action bar标签。有三个片段,当我向前滑动时,它会正确加载片段,当我向后滑动时,它不会加载片段。 它显示了,不幸的是应用已停止。
片段1:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
<FrameLayout
android:id="@+id/fram_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/btn_draw_State"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Free Draw" />
<Button
android:id="@+id/btn_erase_State"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="Free Erase" />
<Button
android:id="@+id/btn_location_State"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Choose Current Location" />
<Button
android:id="@+id/btn_check_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="Check Status of user" />
</FrameLayout>
片段2:此xml用于片段2
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff8400" >
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Design Games Screen"
android:textSize="20dp"
android:layout_centerInParent="true"/>
片段:这包含片段3 xml编码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#17df0d"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="Design Movies Screen"
android:textSize="20dp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="49dp"
android:layout_marginLeft="91dp"
android:text="Button" />
logcat的:
05-06 09:46:21.451: E/AndroidRuntime(10047): FATAL EXCEPTION: main
05-06 09:46:21.451: E/AndroidRuntime(10047): Process: com.safetravelling.norton, PID: 10047
05-06 09:46:21.451: E/AndroidRuntime(10047): android.view.InflateException: Binary XML file line #6: Error inflating class fragment
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
05-06 09:46:21.451: E/AndroidRuntime(10047): at com.safetravelling.norton.DrawPathFragment.onCreateView(DrawPathFragment.java:57)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1280)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:550)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:509)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:490)
05-06 09:46:21.451: E/AndroidRuntime(10047): at com.safetravelling.norton.MainActivity.onTabSelected(MainActivity.java:75)
05-06 09:46:21.451: E/AndroidRuntime(10047): at com.android.internal.app.WindowDecorActionBar.selectTab(WindowDecorActionBar.java:624)
05-06 09:46:21.451: E/AndroidRuntime(10047): at com.android.internal.app.WindowDecorActionBar$TabImpl.select(WindowDecorActionBar.java:1210)
05-06 09:46:21.451: E/AndroidRuntime(10047): at com.android.internal.widget.ScrollingTabContainerView$TabClickListener.onClick(ScrollingTabContainerView.java:546)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.view.View.performClick(View.java:4780)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.view.View$PerformClick.run(View.java:19866)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.os.Handler.handleCallback(Handler.java:739)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.os.Handler.dispatchMessage(Handler.java:95)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.os.Looper.loop(Looper.java:135)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.app.ActivityThread.main(ActivityThread.java:5254)
05-06 09:46:21.451: E/AndroidRuntime(10047): at java.lang.reflect.Method.invoke(Native Method)
05-06 09:46:21.451: E/AndroidRuntime(10047): at java.lang.reflect.Method.invoke(Method.java:372)
05-06 09:46:21.451: E/AndroidRuntime(10047): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
05-06 09:46:21.451: E/AndroidRuntime(10047): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
05-06 09:46:21.451: E/AndroidRuntime(10047): Caused by: java.lang.IllegalArgumentException: Binary XML file line #6: Duplicate id 0x7f0b0019, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
05-06 09:46:21.451: E/AndroidRuntime(10047): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
05-06 09:46:21.451: E/AndroidRuntime(10047): ... 29 more