我想在YouTubeplayerView
中将RecyclerView
整合到Fragment中。
我已经在libs文件夹中下载并添加了YouTubeAndroidPlayerApi.jar
,并将build.gradle
更新为compile files('libs/YouTubeAndroidPlayerApi.jar')
。
list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
app:cardCornerRadius="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Header View -->
<RelativeLayout
android:id="@+id/rlMessageHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/default_margin_padding_min">
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/nivFromAvatar"
android:layout_width="@dimen/avatar_image_size"
android:layout_height="@dimen/avatar_image_size"
android:contentDescription="@string/str_image"
android:src="@drawable/ic_tmp_logo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/default_margin_padding"
android:layout_toRightOf="@+id/nivFromAvatar"
android:orientation="vertical">
<TextView
android:id="@+id/tvFromHeaderName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_from_header_name"
android:textSize="@dimen/message_header_name_text_size_max" />
<TextView
android:id="@+id/tvSentTimeStamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_sent_timestamp"
android:textSize="@dimen/message_header_name_text_size_min" />
</LinearLayout>
</RelativeLayout>
<!-- Content View -->
<LinearLayout
android:id="@+id/llContentView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tvContentTextValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/default_margin_padding_min"
android:text="@string/str_content_value"
android:textSize="@dimen/message_header_name_text_size" />
<FrameLayout
android:id="@+id/flItemCardNormalMedia"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/nivContentImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/str_image" />
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/ytpvItemCard"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
</LinearLayout>
<!-- Action View -->
<LinearLayout
android:id="@+id/llActionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/llActionNormal"
layout="@layout/action_normal"
android:visibility="gone" />
<include
android:id="@+id/llActionRatting"
layout="@layout/action_rating"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
当我运行该项目时,我收到以下错误:
12-08 16:40:40.994 18436-18436/com.waysay E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.waysay, PID: 18436
android.view.InflateException: Binary XML file line #79: Binary XML file line #79: Error inflating class com.google.android.youtube.player.YouTubePlayerView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.waysay.adapters.RecyclerAdapterMessage.onCreateViewHolder(RecyclerAdapterMessage.java:48)
at com.waysay.adapters.RecyclerAdapterMessage.onCreateViewHolder(RecyclerAdapterMessage.java:33)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5228)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4453)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2900)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3071)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1627)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1037)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:747)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1156)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:760)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2171)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1931)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl
如果您愿意,我也可以向您展示RecyclerViewAdapter
的代码。
感谢..