2017-08-17 8 views

答えて

0

ことはあなたのbuild.gradle

buildscript { 
    repositories { 
     jcenter() 
    } 
} 

dependencies { 
    compile 'com.github.aakira:expandable-layout:[email protected]' 
} 

作成したXMLファイル

<com.github.aakira.expandablelayout.ExpandableRelativeLayout 
    android:id="@+id/expandableLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:ael_expanded="false" 
    app:ael_duration="500" 
    app:ael_interpolator="bounce" 
    app:ael_orientation="vertical"> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="sample" /> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/text" 
     android:text="sample2" /> 
</com.github.aakira.expandablelayout.ExpandableRelativeLayout> 

追加Javaコードに依存関係を追加します

ExpandableLinearLayout expandableLayout 
= (ExpandableLinearLayout) findViewById(R.id.expandableLayout); 

child.setText("Sets text from a server"); 
expandableLayout.initLayout(); // Recalculate size of children 

// recycler view 
// you must set a ViewHolder#setIsRecyclable(false) and ExpandableLinearLayout#setInRecyclerView(true) 

@Override 
public void onBindViewHolder(final ViewHolder holder, final int position) { 
    holder.setIsRecyclable(false); 
    holder.expandableLinearLayout.setInRecyclerView(true); 
} 
0

このメソッドを子ビューに使用するだけです。

private void animateView(final View target, final int type) { 
     Animation anim = new ExpandCollapseAnimation(target,type); 
     anim.setDuration(getAnimationDuration()); 
     anim.setAnimationListener(new AnimationListener() { 

     @Override 
     public void onAnimationStart(Animation animation) {} 

     @Override 
     public void onAnimationRepeat(Animation animation) {} 

     @Override 
     public void onAnimationEnd(Animation animation) { 
      if (type == ExpandCollapseAnimation.EXPAND) { 
       if (parent instanceof ListView) { 
        ListView listView = (ListView) parent; 
        int movement = target.getBottom(); 

        Rect r = new Rect(); 
        boolean visible = target.getGlobalVisibleRect(r); 
        Rect r2 = new Rect(); 
        listView.getGlobalVisibleRect(r2); 

        if (!visible) { 
         listView.smoothScrollBy(movement, getAnimationDuration()); 
        } else { 
         if (r2.bottom == r.bottom) { 
          listView.smoothScrollBy(movement,getAnimationDuration()); 
         } 
         } 
       } 
      } 
     } 
    }); 
    target.startAnimation(anim); 
} 
関連する問題