今天使用ExpandableTextView这个控件遇到一个奇葩问题。
我是将ExpandableTextView放到了一个item的布局中,要填充到ListView里。结果报了
android.view.InflateException: Binary XML file line #2: Error
inflating class
com.connxun.chinamedicine.modules.product.widget.EvaluateItemView
这个错误。
报错的代码是这样的:
LayoutInflater.from(context).inflate(R.layout.item_prod_eval, this);
解决过程省略了,直接上解决方案:
ExpandableTextView只能作为根节点,重新放到一个xml布局中,然后include到需要的地方就好了。。。
item.xml
<?xml version="1.0" encoding="UTF-8"?>
<com.ms.square.android.expandabletextview.ExpandableTextView expandableTextView:animDuration="200" expandableTextView:maxCollapsedLines="4" android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/expand_text_view" xmlns:expandableTextView="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@id/expandable_text" android:textColor="#666666" android:textSize="16sp" android:layout_marginRight="10dp" android:layout_marginLeft="10dp"/>
<ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@id/expand_collapse" android:background="@android:color/transparent" android:layout_gravity="right|bottom" android:padding="16dp"/>
</com.ms.square.android.expandabletextview.ExpandableTextView>
引用:
<include layout="@layout/item"/>