minSDK=10 using DesignSupportLibrary.
我使用RecycleView,在适配器中,当我在onCreateViewHolder()方法中膨胀布局视图时,我在这个布局的xml文件中使用RippleDrawable,我得到了这个错误。
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)
但是当我从listtitem视图的xml中删除RippleDrawable时,它将工作,所以我不能使用涟漪效应。
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>
如果有人给答案,那将是伟大的,我的荣幸。
RippleDrawable在API Level 21中添加,不幸的是,这还不是支持库的一部分。它很可能会在未来的更新中出现,但没有公布时间框架。
幸运的是,已经有一些自定义实现可用:
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
所以你可以尝试其中一个或谷歌其他"材料部件"。