片段中的重复 ID YouTubePlayerSupportFragment
Posted
技术标签:
【中文标题】片段中的重复 ID YouTubePlayerSupportFragment【英文标题】:Duplicated ID in Fragment YouTubePlayerSupportFragment 【发布时间】:2014-10-17 14:26:21 【问题描述】:我正在尝试使用 API Youtube 执行播放视频,但在 XML Duplicated ID 0x7f080039 中出现错误。知道如何解决这个问题吗?
我的 Fragment 扩展了 YouTubePlayerSupportFragment :
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
System.out.println();
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.feed_video, container, false);
YouTubePlayerSupportFragment youTubePlayerFragment =
(YouTubePlayerSupportFragment) getChildFragmentManager().findFragmentById(R.id.youtube_fragment);
youTubePlayerFragment.initialize(DeveloperKey.DEVELOPER_KEY, this);
return view;
我的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_
android:orientation="vertical">
<fragment
class="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:id="@+id/youtube_fragment"
android:layout_
android:layout_ />
<ListView
android:id="@+id/feed_video_list"
android:layout_
android:layout_
android:divider="#424346"
android:dividerHeight="2dp">
</ListView>
</LinearLayout>
我的错误:
Process: br.com.dotazone, PID: 18375
android.view.InflateException: Binary XML file line #8: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at br.com.dotazone.view.fragment.ChannelYoutubeFragment.onCreateView(ChannelYoutubeFragment.java:79)
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.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:478)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
at android.view.View.measure(View.java:17350)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:17350)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:704)
at android.view.View.measure(View.java:17350)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:17350)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:17350)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2505)
at android.view.View.measure(View.java:17350)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2175)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1316)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1513)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1200)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6388)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:573)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Binary XML file line #8: Duplicate id 0x7f080039, tag null, or parent id 0x0 with another fragment for com.google.android.youtube.player.YouTubePlayerSupportFragmentyer.YouTubePlayerSupportFragment
【问题讨论】:
当布局包含<fragment>
时,您不能将布局扩展为片段。仅当动态添加到片段时才支持嵌套片段。阅读 嵌套片段 @developer.android.com/about/versions/android-4.2.html
【参考方案1】:
此错误发生在已在 layout 中定义的嵌套 Fragment 上,尝试从 Xml Layout 中删除您的 Fragment 并将其替换为 FrameLayout 作为 PlaceHolder,然后在代码中动态实例化您的 Fragment。
【讨论】:
@DouglasMesquita 你实施成功了吗?如果可以,您能否分享解决方案,因为当我尝试在每一行中播放视频时,它不会保持队列的位置。 @AnantShah 是的。我的代码在 [github] [1] [1]:github.com/douglasalipio/dotazone/blob/master/dota-zone/… @DouglasMesquita 您的 github 链接显示 404 错误,请更新链接并感谢您分享链接。 @AnantShah 是的。我在 Github 上的代码Inline Link以上是关于片段中的重复 ID YouTubePlayerSupportFragment的主要内容,如果未能解决你的问题,请参考以下文章
ID、标签 null 或父 ID 与 com.google.android.gms.maps.MapFragment 的另一个片段重复