2016-07-27 1 views
1

간단한 설정 : RecyclerView에 각각 TextView을 포함하는 항목 목록이 표시됩니다. 텍스트보기 중 하나는 여러 줄을 가질 수 있습니다. 처음에는 android:maxLines이 1로 설정되었습니다. 항목의 클릭 수신기에서 최대 1 줄과 최대 무한대 (전체 내용 표시) 사이를 전환합니다. 그것은 움직이지 않는 것을 제외하고는 잘 동작합니다. 내 뷰 계층 구조에서 다른 레벨에 android:animateLayoutChanges을 추가하려고했지만 애니메이션은 여전히 ​​사용하지 않았습니다.android : animateLayoutChanges가 TextView의 maxLines를 변경할 때 RecyclerView에서 작동하지 않습니다.

제 생각에 대해 알려주세요.

참고 : 수동 애니메이션을 프로그래밍 할 수 있지만 Android에서이 xml 속성으로 처리하도록합니다. MY 코드


일부 :

내 목록 항목 레이아웃 : 나는 comments 텍스트 뷰를 확장하고

내보기 홀더에서
<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rootCard" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
    android:layout_marginTop="5dp" 
    android:layout_marginBottom="5dp"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:animateLayoutChanges="true" 
     android:padding="10dp"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp"> 

      <TextView 
       android:id="@+id/destination" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_marginEnd="36dp" 
       android:layout_marginRight="36dp" 
       android:textStyle="bold" 
       android:ellipsize="end" 
       android:maxLines="1" 
       android:textSize="25sp" /> 

      <ImageButton 
       android:id="@+id/editButton" 
       android:layout_width="24dp" 
       android:layout_height="24dp" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentTop="true" 
       android:src="@drawable/ic_edit" 
       android:contentDescription="@string/edit_button_content_descr" 
       android:background="?attr/selectableItemBackgroundBorderless" /> 
     </RelativeLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/dateRange" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="17sp" /> 

      <Space 
       android:layout_width="0dp" 
       android:layout_height="0dp" 
       android:layout_weight="1"/> 

      <TextView 
       android:id="@+id/daysLeft" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="20dp" 
       android:layout_marginStart="20dp" 
       android:background="@drawable/days_left_background" 
       android:gravity="end" 
       android:layout_gravity="end" 
       android:textColor="@android:color/white" 
       android:textSize="15sp" 
       android:textStyle="bold"/> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/comments" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="10dp" 
      android:textSize="15sp" 
      android:ellipsize="end" 
      android:maxLines="1" /> 
    </LinearLayout> 

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

: 여기

rootCard.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      comments.setMaxLines((comments.getMaxLines() == 1) ? Integer.MAX_VALUE : 1); 
     } 
    }); 

가있다 Recycler가 포함 된 내 조각의 레이아웃 보기 :

<?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="match_parent" 
    android:paddingBottom="@dimen/common_vertical_margin" 
    android:paddingLeft="@dimen/common_horizontal_margin" 
    android:paddingRight="@dimen/common_horizontal_margin" 
    android:paddingTop="@dimen/common_vertical_margin" 
    xmlns:tools="http://schemas.android.com/tools"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/tripList" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:listitem="@layout/list_item_trip" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@drawable/ic_add" /> 

</RelativeLayout> 

답변

3

당신은 어댑터의 notifyItemChanged()를 호출하지 않았기 때문에 안드로이드 뭔가가 변경되었습니다 및 애니메이션해야한다는 것을 인식하지 못합니다. 귀하의 경우는 CardView입니다 -

rootCard.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     comments.setMaxLines((comments.getMaxLines() == 1) ? Integer.MAX_VALUE : 1); 
     notifyItemChanged(viewHolder.getAdapterPosition()); 
    } 
}); 

이 레이아웃의 루트보기로 animateLayoutChanges을 설정하려고 작동하지 않을 경우

이 : 그래서 당신이 필요로하는 모든 당신의 maxLines 속성을 변경 한 후이 메서드 호출을 추가하는 것입니다.

+0

감사합니다. – frangulyan

관련 문제