2017-08-14 112 views
0

我不知道为什么我有渲染错误加入ExpandableTextView渲染错误在ExpandableTextView

<com.ms.square.android.expandabletextview.ExpandableTextView 
     android:id="@+id/expand_text_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/first_linear" 
     expandableTextView:maxCollapsedLines="4" 
     expandableTextView:animDuration="200"> 

     <TextView 
      android:id="@+id/expandable_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="10dp" 
      android:layout_marginTop="5dp"/> 


    </com.ms.square.android.expandabletextview.ExpandableTextView> 

依赖性时,compile 'com.ms-square:expandableTextView:0.1.4'

下面是完整的XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_marginTop="10dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <RelativeLayout 
     android:id="@+id/question_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="10dp"> 

     <LinearLayout 
      android:id="@+id/first_linear" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="@dimen/activity_horizontal_margin"> 

      <ImageView 
       android:id="@+id/up_vote" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/vote" 
       android:src="@drawable/vote_up" /> 

      <TextView 
       android:id="@+id/vote_number" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dp" 
       android:text="12" 
       android:textSize="16sp" /> 

      <ImageView 
       android:id="@+id/accepted_answer" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/accepted" 
       android:scaleType="fitXY" 
       android:src="@drawable/correct" /> 

     </LinearLayout> 

     <com.ms.square.android.expandabletextview.ExpandableTextView 
      xmlns:expandableTextView="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/expand_text_view" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/first_linear" 
      expandableTextView:maxCollapsedLines="4" 
      expandableTextView:animDuration="200"> 

      <TextView 
       android:id="@+id/expandable_text" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       android:layout_marginTop="5dp"/> 


     </com.ms.square.android.expandabletextview.ExpandableTextView> 

    </RelativeLayout> 

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

你能写出完整的错误日志吗? –

+0

只是当我将ExpandableTextView标记添加到XML文件时发生了此错误,无非就是这样 –

+0

已添加答案..试试这个应该可以工作.. –

回答

0

也许你错过了命名空间错误。尝试使用这一个 你可以去here的解释。

<com.ms.square.android.expandabletextview.ExpandableTextView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:expandableTextView="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/expand_text_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    expandableTextView:maxCollapsedLines="4" 
    expandableTextView:animDuration="200"> 
    <TextView 
     android:id="@id/expandable_text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:textSize="16sp" 
     android:textColor="#666666" /> 
    <ImageButton 
     android:id="@id/expand_collapse" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:layout_gravity="right|bottom" 
     android:background="@android:color/transparent"/> 
</com.ms.square.android.expandabletextview.ExpandableTextView> 
+0

我刚才写的代码是在一个CardView里面的RelativeLayout,是有关问题 ?? –

+0

您的xml文件根目录中是否有xmlns的expandabletextview? –

+0

它解决了当我添加ImageButton时,我并不认为ImageButton是强制性的,因为我想添加一个“显示更多”TextView而不是它,但是感谢您的帮助 –