二进制XML文件第35行:膨胀类TextView时出错

时间:2018-07-20 15:30:43

标签: android

大家好,我的应用程序可以在android 7和8上运行,但是在android 5中会崩溃。  我有一个Recyclerview,它从凌空的服务器上获取数据。 我尝试了所有方法来解决此问题,但它们对我没有用。 像清理和重建,或将android.enableAapt2 = false添加到gradle和..... 日志猫:

Process: app.karyab.tabriz.karyab, PID: 6499

android.view.InflateException: Binary XML file line #35: Error inflating 
class TextView

at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
                                                                        at app.karyab.tabriz.karyab.AdsAdapter.onCreateViewHolder(AdsAdapter.java:76)
                                                                        at app.karyab.tabriz.karyab.AdsAdapter.onCreateViewHolder(AdsAdapter.java:26)
                                                                        at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6685)
                                                                        at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5869)
                                                                        at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5752)
                                                                        at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5748)
                                                                        at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2232)
                                                                        at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1559)
                                                                        at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1519)
                                                                        at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:614)
                                                                        at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
                                                                        at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3529)
                                                                        at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4082)
                                                                        at android.view.View.layout(View.java:15671)
                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5038)
                                                                        at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:606)
                                                                        at android.view.View.layout(View.java:15671)
                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5038)
                                                                        at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
                                                                        at android.view.View.layout(View.java:15671)
                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5038)
                                                                        at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1171)
                                                                        at android.view.View.layout(View.java:15671)
                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5038)
                                                                        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
                                                                        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
                                                                        at android.view.View.layout(View.java:15671)
                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5038)
                                                                        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
                                                                        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
                                                                        at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
                                                                        at android.view.View.layout(View.java:15671)
                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5038)
                                                                        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
                                                                        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
                                                                        at android.view.View.layout(View.java:15671)
                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5038)
                                                                        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
                                                                        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
                                                                        at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
                                                                        at android.view.View.layout(View.java:15671)
                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5038)
                                                                        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
                                                                        at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
                                                                        at android.view.View.layout(View.java:15671)
                                                                        at android.view.ViewGroup.layout(ViewGroup.java:5038)
                                                                        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)
                                                                        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)
                                                                        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
                                                                        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
                                                                        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
                                                                        at android.view.Choreographe

我的适配器:

public class AdsAdapter extends RecyclerView.Adapter<AdsAdapter.MyViewHolder> {


private List<AdsModel> adslist;
Context con;


public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    public TextView time, title,city,vip,hour;


    private ItemClickListener clickListener;

    public MyViewHolder(View view) {
        super(view);
        view.setOnClickListener(this);

        time = view.findViewById(R.id.time);
        title = view.findViewById(R.id.title);
        city =  view.findViewById(R.id.city);
        vip = view.findViewById(R.id.vip);
        hour =  view.findViewById(R.id.hour);


    }

    public void setClickListener(ItemClickListener itemClickListener) {
        this.clickListener = itemClickListener;

    }

    @Override
    public void onClick(View view) {
        clickListener.onClick(view, getPosition(), false);
    }


}


public AdsAdapter(List<AdsModel> adslist, Context con) {
    this.adslist = adslist;
    this.con = con;

}

@Override
public AdsAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.ads_item, parent, false);

    return new AdsAdapter.MyViewHolder(itemView);
}

@Override
public void onBindViewHolder(AdsAdapter.MyViewHolder holder, int position) {

    final AdsModel ads = adslist.get(position);


    holder.title.setText(ads.getTitle());
    holder.city.setText(ads.getCity());
    Server server = new Server();

    holder.hour.setText(server.Caldate(Integer.parseInt(ads.getDate())));
    holder.time.setText(ads.getTime());

    if(ads.getType().equals("2")){

        holder.title.setTextColor(Color.parseColor("#ef970f"));
    }
    else{
        holder.vip.setVisibility(View.INVISIBLE);
    }



    holder.setClickListener(new ItemClickListener() {
        @Override
        public void onClick(View view, int position, boolean isLongClick) {
            //  Toast.makeText(con,""+ads.getField(), Toast.LENGTH_LONG).show();
            Intent i = new Intent(con,Ads_Page.class);
            i.putExtra("ads",ads);
            con.startActivity(i);


        }
    });
}

ads_item布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="5dp">


<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="2dp"
    app:cardBackgroundColor="#fff"
    app:cardCornerRadius="4dp"
    >
    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="7dp">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/title"
            android:text="df"
            android:layout_marginTop="4dp"
            android:layout_marginRight="4dp"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            android:layout_marginLeft="12dp"
            android:textSize="18sp"
            android:textColor="@color/title"
            android:gravity="right"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/city"
            app:layout_constraintRight_toRightOf="@+id/title"
            app:layout_constraintTop_toBottomOf="@+id/title"
            android:layout_marginTop="7dp"
            android:textSize="16sp"
            android:text="sd"
            android:layout_marginRight="5dp"
            android:textColor="@color/grey"
            android:drawableRight="@drawable/location"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/time"
            app:layout_constraintRight_toRightOf="@+id/city"
            app:layout_constraintTop_toBottomOf="@+id/city"
            android:layout_marginTop="7dp"
            android:textSize="16sp"
            android:textColor="@color/grey"
            android:text="sd"
            android:drawableRight="@drawable/date"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/hour"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/city"
            android:layout_marginTop="7dp"
            android:layout_marginLeft="15dp"
            android:textColor="@color/grey"

            android:textSize="16sp"
            android:text="sd"
            android:drawableRight="@drawable/date"
            />

        <TextView
            android:layout_width="60dp"
            android:layout_height="wrap_content"
            android:id="@+id/vip"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/title"
            android:layout_marginTop="4dp"
            android:textSize="16sp"
            android:text="ویژه"
            android:padding="2dp"
            android:gravity="center"
            android:layout_marginRight="5dp"
            android:textColor="#fff"
            android:background="@drawable/vip_style"
            android:layout_marginLeft="15dp"
            />

    </android.support.constraint.ConstraintLayout>

</android.support.v7.widget.CardView>

主要布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f9f9f9"
tools:context="app.karyab.tabriz.karyab.MainActivity">

<include android:id="@+id/tool"
layout="@layout/toolbar"/>

<android.support.constraint.ConstraintLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  android:weightSum="1"
  android:layout_below="@+id/tool"
  android:padding="4dp"
  android:background="@color/colorPrimary"
  android:id="@+id/filter">

  <android.support.constraint.Guideline
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/gui"
    app:layout_constraintGuide_percent="0.5"/>
  <Spinner
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:spinnerMode="dialog"
    android:id="@+id/gender"
    android:background="@color/colorPrimary"
    app:layout_constraintRight_toRightOf="@+id/gui"
    app:layout_constraintLeft_toLeftOf="parent"
    />
   <Spinner
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:id="@+id/timeline"
    android:spinnerMode="dialog"
    app:layout_constraintRight_toRightOf="parent"
    android:background="@color/colorPrimary"
    android:layout_marginLeft="30dp"
    app:layout_constraintLeft_toLeftOf="@+id/gui"
    />
   </android.support.constraint.ConstraintLayout>

   <android.support.v4.widget.SwipeRefreshLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/pullref"
    android:layout_below="@+id/filter"
    >
  <android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/recc"/>
  </android.support.v4.widget.SwipeRefreshLayout>

  </RelativeLayout>

1 个答案:

答案 0 :(得分:0)

您没有关闭</RelativeLayout>在ads_item上的相对布局