2017-08-14 120 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而不是它,但是感謝您的幫助 –