java共享元素从recycelrview到activity的转换

ikfrs5lh  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(325)

请告诉我为什么会这样?我做错什么了?屏幕视频
听众

public interface NoteListener {
void onNoteClicked(Note note, int position, RelativeLayout noteLayout);

}
适配器

NoteViewHolder(@NonNull View itemView) {
        ...
        relativeLayoutNote = itemView.findViewById(R.id.rl_note);

        itemView.setOnClickListener(v -> noteListener.onNoteClicked(sortedList.get(getAdapterPosition()),
                getAdapterPosition(),  relativeLayoutNote));
    }

主要活动

@Override
public void onNoteClicked(Note note, int position, RelativeLayout noteLayout) {
    if (!isClick) {
        DetailNoteActivity.start(this, note, findViewById(R.id.rl_note));
        isClick = true;
    }
}

细节活动

public static void start(Activity caller, Note note, RelativeLayout noteLayout) {
    Intent intent = new Intent(caller, DetailNoteActivity.class);
    ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(
            caller, noteLayout, "note");
    if (note != null) {
        intent.putExtra(NOTE, note);
    }
    caller.startActivity(intent, options.toBundle());
}

项目注解

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
android:background="@drawable/background_note"
android:transitionName="note">...

活动详细信息

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:transitionName="note"
        android:animateLayoutChanges="true">...
pnwntuvh

pnwntuvh1#

我决定用下面的方法,可能很笨拙,如果有别的方法请写。在mainactivity中添加了以下内容:

public class MainActivity extends AppCompatActivity implements NoteListener {
...
private RelativeLayout noteLayout;
...
@SuppressLint("SupportAnnotationUsage")
@AnimRes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ....
    noteLayout = findViewById(R.id.rl_note);
    ...

@Override
public void onNoteClicked(Note note, RelativeLayout noteLayout) {
    this.noteLayout = noteLayout;
    if (!isClick) {
        DetailNoteActivity.start(this, note, noteLayout);
        isClick = true;
    }
}

相关问题