Expand and collapse animation

时间:2016-10-20 12:37:58

标签: android android-animation

I'am trying to achieve expand and collapse animation in RecyclerView and tried this solution but it's have a lot of problems and i can't use it anymore, Also o tried a lot of solutions but it's not working as requested from customer like scale the view using this to collapse the view:

view.animate().scaleY(1 / item.getHeight()).setDuration(300).withEndAction(new Runnable() {
    @Override
    public void run() {
        item.setVisibility(View.GONE);
    }
});

I want the animation exactly like this:

Image

Is there any way to do this?

1 个答案:

答案 0 :(得分:0)

你总是可以使用第三方库来实现一个很好的实现,但我用这种方法来减少我的应用程序中的库量。

 int mExpandedPosition = -1;
 int OldOpen = -1;
 @Override
        public void onBindViewHolder(final Example.ViewHolder holder, final int position) {


//what ever your bind logic goes here

            holder.textViewKey.setText(allData.get(position).get("key"));

//expanding this view will collapse any other one open`

            final boolean isExpanded = position==mExpandedPosition;
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                   OldOpen = mExpandedPosition;
                    if (isExpanded == true) {
                        mExpandedPosition = -1;
                    } else {
                        mExpandedPosition = position;
                    }
                    TransitionManager.beginDelayedTransition(CompanyDetailsRecycler);
                    if (OldOpen != -1)
                        notifyItemChanged(OldOpen);
                    notifyItemChanged(position);
                }
            });
相关问题