minSDK=10 使用DesignSupportLibrary。
我使用 RecycleView,在适配器中,当我在onCreateViewHolder()方法中膨胀布局视图并在此布局的 xml 文件中 使用RippleDrawable时,我收到了这个错误。
日志猫
E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.LinearLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at com.demo_toolbarall.RespondScrollEvent$Myadapter.onCreateViewHolder(RespondScrollEvent.java:83)
at com.demo_toolbarall.RespondScrollEvent$Myadapter.onCreateViewHolder(RespondScrollEvent.java:70)
但是当我从 listItem 视图的 xml 中删除 RippleDrawable 时,它会起作用,所以我不能使用 Ripple Effect。
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripples"
android:gravity="center_vertical"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/avatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="16dp"/>
<TextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceListItem"/>
</LinearLayout>
我的适配器类
class Myadapter extends RecyclerView.Adapter<Myadapter.ViewHolder> {
Context mContext;
List<String> mList;
View view;
public Myadapter(Context mContext, List<String> mList) {
this.mContext = mContext;
this.mList = mList;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
view = LayoutInflater.from(RespondScrollEvent.this).inflate(R.layout.list_item, parent, false);
return new ViewHolder(view);
}
涟漪.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/window_background2">
<item>
<shape>
<solid android:color="#FFFFFF" />
</shape>
</item>
</ripple>
如果有人给出答案,那就太好了,我也很荣幸。