android.view.InflateException二进制XML文件行#0:错误夸大类原因:java.lang.reflect.InvocationTargetException
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="10dp"
app:cardBackgroundColor="@color/cardview_light_background"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:backgroundSplit"
android:padding="10dp"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name"
android:textColor="@android:color/black"
android:textSize="15sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/type"
android:textColor="@android:color/black"
android:textSize="15sp"
android:textStyle="normal"/>
</LinearLayout>
</android.support.v7.widget.CardView>
适配器类:
class LoadingViewHolder extends RecyclerView.ViewHolder{
public ProgressBar progressBar;
public LoadingViewHolder(View itemView) {
super( itemView );
progressBar = (ProgressBar)itemView.findViewById( R.id.progressBar );
}
}
class EmpViewHolder extends RecyclerView.ViewHolder{
public TextView name , type;
public EmpViewHolder(View itemView) {
super( itemView );
name = (TextView)itemView.findViewById( R.id.fname);
type = (TextView)itemView.findViewById( R.id.lname );
}
}
public class MyAdaptor extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final int view_type_item = 0 , view_type_loading = 1;
ILoadMore iLoadMore;
boolean isLoading;
Activity activity;
List<Employee> employees;
int visibleThreshold = 5;
int lastVisibleItem , totalItemCount;
public MyAdaptor(RecyclerView recyclerView , Activity activity, List<Employee> employees) {
this.activity = activity;
this.employees = employees;
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager)recyclerView.getLayoutManager();
recyclerView.addOnScrollListener( new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled( recyclerView, dx, dy );
totalItemCount = linearLayoutManager.getItemCount();
lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
if(!isLoading && totalItemCount <= (lastVisibleItem + visibleThreshold))
{
if (iLoadMore != null)
iLoadMore.onLoadMore();
isLoading = true;
}
}
} );
}
@Override
public int getItemViewType(int position) {
return employees.get(position) == null ? view_type_loading:view_type_item;
}
public void setiLoadMore(ILoadMore iLoadMore) {
this.iLoadMore = iLoadMore;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if(viewType == view_type_item)
{
View view = LayoutInflater.from( activity )
.inflate(R.layout.employee_layout , parent , false );
return new EmpViewHolder( view );
}
else if (viewType == view_type_loading){
View view = LayoutInflater.from( activity )
.inflate( R.layout.employee_loading , parent, false );
return new LoadingViewHolder( view );
}
return null;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof EmpViewHolder)
{
Employee employee = employees.get(position);
EmpViewHolder viewHolder = (EmpViewHolder) holder;
viewHolder.name.setText( employees.get(position).getFname() );
viewHolder.type.setText( employees.get( position ).getType() );
}
else if (holder instanceof LoadingViewHolder)
{
LoadingViewHolder loadingViewHolder = (LoadingViewHolder)holder;
loadingViewHolder.progressBar.setIndeterminate( true );
}
}
@Override
public int getItemCount() {
return employees.size();
}
public void setLoaded(){
isLoading = false;
}
}
Adpoter.java结尾
-------堆栈跟踪---------------------
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.foodorderingapp, PID: 22889
android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
com.example.user.foodorderingapp.EmployeeFiles.MyAdaptor.onCreateViewHolder(MyAdaptor.java:91)
答案 0 :(得分:0)
android.R.attr.backgroundSplit用于拆分的ActionBar(在布局底部显示额外的按钮,等等)。它确实定义了背景,但是根据文档,它可能是在引用任何类型的资源,任何类型的主题,或者甚至只是笔直的十六进制颜色字符串。
LinearLayout的背景字段只能使用颜色,颜色参考或可绘制参考。