我正在使用Android应用程序,在这里我正在使用RecyclerView。我有一个用于RecyclerView的item.xml。
item.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardView="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/userpopstcardview"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
cardView:cardElevation="2dp"
cardView:cardCornerRadius="5dp"
cardView:cardBackgroundColor="#fff"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/listview_corner"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/user_placeholder"
android:layout_margin="10dp"
android:id="@+id/circleView"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_marginLeft="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:text="Jasmine"
android:textSize="20sp"
android:textStyle="bold"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#929292"
android:maxLines="2"
android:textSize="14sp"
android:textStyle="normal"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#929292"
android:text=""
android:textSize="14sp"
android:textStyle="normal"
/>
<TextView
android:id="@+id/hours_minuts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#929292"
android:text=""
android:textSize="14sp"
android:textStyle="normal"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#929292"
android:text=""
android:textSize="14sp"
android:textStyle="normal"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/massage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#000"
android:padding="10dp"
android:textSize="16sp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#303030">
<ImageView
android:id="@+id/attachment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:tint="#00000000"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/player_toolbar"
android:background="#30000000"
android:layout_gravity="bottom"
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
>
<TextView
android:id="@+id/audioTime"
android:text="00:00"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:layout_width="wrap_content"
android:layout_height="@dimen/avatar_size"
android:layout_alignParentRight="true"
android:gravity="center"/>
<RelativeLayout
android:id="@+id/player_control"
android:layout_alignParentLeft="true"
android:layout_width="@dimen/avatar_size"
android:layout_height="@dimen/avatar_size"
android:layout_marginLeft="10dp"
>
<ImageView
android:id="@+id/player_state"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/play"
android:tint="#00000000"
/>
</RelativeLayout>
<TextView
android:id="@+id/selected_title"
android:text=""
android:paddingLeft="8dp"
android:layout_toLeftOf="@id/audioTime"
android:layout_toRightOf="@id/player_control"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp"
android:background="#fff">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/likespoints"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#929292"
android:textSize="14sp"/>
<TextView
android:id="@+id/likeList"
android:background="@drawable/textview_effect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Likes"
android:textColor="#929292"
android:textSize="14sp"
android:layout_marginLeft="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="30dp">
<TextView
android:id="@+id/commentspoints"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#929292"
android:textSize="14sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments"
android:textColor="#929292"
android:textSize="14sp"
android:layout_marginLeft="5dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_height="0.5dp"
android:layout_width="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#eeeeee"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="@+id/like"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Like"
android:gravity="center"
android:layout_gravity="center"
android:textSize="14sp"
android:textColor="#929292"
android:padding="10dp"
android:clickable="true"
android:background="@drawable/textview_effect"/>
</LinearLayout>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0.5dp">
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="#eeeeee"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="@+id/comment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Comment"
android:gravity="center"
android:layout_gravity="center"
android:textSize="14sp"
android:textColor="#929292"
android:padding="10dp"
android:clickable="true"
android:background="@drawable/textview_effect"/>
</LinearLayout>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0.5dp">
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="#eeeeee"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="@+id/share"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Share"
android:gravity="center"
android:layout_gravity="center"
android:textSize="14sp"
android:textColor="#929292"
android:padding="10dp"
android:clickable="true"
android:background="@drawable/textview_effect"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
我使用 onCreateViewHolder(ViewGroup viewGroup,int viewType)
中的以下代码对item.xml进行了膨胀View itemViewTextAudio = inflater.inflate(R.layout.item, viewGroup, false);
但它正在崩溃。我访问了Stackoverflow上的很多帖子,但没有运气。
LogCat:
Process: com.musomeet, PID: 27659
android.view.InflateException: Binary XML file line #150: Binary XML file line #150: Error inflating class <unknown>
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.adapter.UserPostAdapter.onCreateViewHolder(UserPostAdapter.java:340)
at com.adapter.UserPostAdapter.onCreateViewHolder(UserPostAdapter.java:30)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5288)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4551)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4461)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1962)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1371)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1334)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:563)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2847)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3145)
at android.view.View.layout(View.java:16636)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
at android.view.View.layout(View.java:16636)
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:16636)
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:16636)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1043)
at android.view.View.layout(View.java:16636)
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:16636)
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:16636)
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:16636)
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:16636)
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:16636)
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$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreograph
修改:
item.xml在基于Lollipop的设备上完美展示,但它没有在基于Marshmallow的Android手机的华为Nexus 6P 上显示。
注意:当我尝试setContentView(R.layout.item)时,在华为Nexus 6P 上工作正常。 但使用下面的代码时会抛出错误:
View itemViewTextAudio = inflater.inflate(R.layout.item, viewGroup, false);