当我使用 DesignSupportLibrary 将 RippleDrawable 与 API 10 一起使用时,列表项布局出现 android.view.InflateException 错误
When i use RippleDrawable with API 10 using DesignSupportLibrary, i got android.view.InflateException error in layout of list item
minSDK=10 使用 DesignSupportLibrary.
我正在使用 RecycleView,在适配器中,当我在 onCreateViewHolder() 方法中膨胀布局视图时,我正在使用 RippleDrawable此布局的 xml 文件出现此错误。
logcat
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>
MyAdapter.class
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);
}
ripples.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>
如果有人回答,那就太好了,我也很荣幸。
在 API 级别 21 中添加了 RippleDrawable,不幸的是,这还不是支持库的一部分。它很可能会出现在未来的更新中,但没有公布时间范围。
幸运的是,几乎没有可用的自定义实现:
https://github.com/traex/RippleEffect
https://github.com/balysv/material-ripple
https://github.com/siriscac/RippleView
https://github.com/ozodrukh/RippleDrawable
包括与旧版本 Android 兼容的 Material 主题小部件集:
https://github.com/keithellis/MaterialWidget
因此您可以尝试其中之一或 google 尝试其他 "material widgets"。
minSDK=10 使用 DesignSupportLibrary.
我正在使用 RecycleView,在适配器中,当我在 onCreateViewHolder() 方法中膨胀布局视图时,我正在使用 RippleDrawable此布局的 xml 文件出现此错误。
logcat
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>
MyAdapter.class
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);
}
ripples.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>
如果有人回答,那就太好了,我也很荣幸。
在 API 级别 21 中添加了 RippleDrawable,不幸的是,这还不是支持库的一部分。它很可能会出现在未来的更新中,但没有公布时间范围。
幸运的是,几乎没有可用的自定义实现:
https://github.com/traex/RippleEffect
https://github.com/balysv/material-ripple
https://github.com/siriscac/RippleView
https://github.com/ozodrukh/RippleDrawable
包括与旧版本 Android 兼容的 Material 主题小部件集:
https://github.com/keithellis/MaterialWidget
因此您可以尝试其中之一或 google 尝试其他 "material widgets"。