【问题标题】:Animation when clicking on the recyclerview element单击 recyclerview 元素时的动画
【发布时间】:2021-02-26 21:48:04
【问题描述】:

当我点击recyclerview 元素时,我需要制作一个类似于下拉列表的动画。在项目 2 xml 标记中,1 是主要的,第二个在单击时变为可见。按照思路,应该是这样的:我点击了元素,它打开了一个dropout动画。再次按下时,它关闭了。还有动画。此刻,元素只是骤然出现,又骤然消失。如果有这种可能性,我不想使用第三方库。我想做类似this

holder.itemView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if (!flag) {
            Intent intent = new Intent(mContext, MessageActivity.class);
            intent.putExtra("userid", user.getId());
            mContext.startActivity(intent);

        } else if(holder.info.getVisibility()==View.GONE) { 
            holder.info.setVisibility(View.VISIBLE);

        } else {
            holder.info.setVisibility(View.GONE);
        }
    }
);

在这部分代码中,我要么打开消息活动,要么打开有关用户的其他信息。

布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:padding="10dp"
    android:layout_height="wrap_content">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/info_about">
            ///Info about users(username and him photo)

        </RelativeLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/info_about"
            android:paddingTop="5dp"
            android:layout_marginTop="45dp"
            android:layout_centerHorizontal="true"
            android:orientation="vertical"
            android:visibility="gone"
            android:id="@+id/info">

            ///Info about users(call_number, email... When i clicked on item)
        </LinearLayout>
    </androidx.cardview.widget.CardView>
</LinearLayout>

【问题讨论】:

    标签: android android-recyclerview android-animation


    【解决方案1】:

    试试这个...

    holder.binding.cardview.setOnClickListener(v -> {
    
    
                        if (holder.binding.expandableView.getVisibility()==View.GONE){
                            TransitionManager.beginDelayedTransition(holder.binding.cardview, new AutoTransition());
                            holder.binding.expandableView.setVisibility(View.VISIBLE);
                        } else {
                            TransitionManager.beginDelayedTransition(holder.binding.cardview, new AutoTransition());
                            holder.binding.expandableView.setVisibility(View.GONE);
    
                        }
    
                        if (holder.binding.playlayout.getVisibility()==View.GONE){
                            TransitionManager.beginDelayedTransition(holder.binding.cardview, new AutoTransition());
                            holder.binding.playlayout.setVisibility(View.VISIBLE);
                        } else {
                            TransitionManager.beginDelayedTransition(holder.binding.cardview, new AutoTransition());
                            holder.binding.playlayout.setVisibility(View.GONE);
    
                        }
    
                    });
                }
    

    【讨论】:

    • 感谢您的回答,但您的解决方案中的绑定是什么?我的 clicklistener 看起来像这样: holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {some code....
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-18
    • 2013-08-24
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多