从RecyclerView过渡看起来很糟糕

时间:2017-03-31 20:37:28

标签: android android-fragments android-recyclerview android-animation android-transitions

在片段之间进行动画制作时,我发现动画片段RecyclerView,视图往往会破坏。

text

仔细观察gif,它将从第二个(中间)片段移动到第一个和第三个片段。了解CardView的部分内容是如何删除的。

有什么方法可以让过渡更顺畅吗?我在RecyclerView.Adapter上阅读了关于数据绑定的内容,以便立即绑定数据,但我不知道这是否有助于这种特殊情况,因为它正在从转换出错误的RecyclerView片段。

MainActivity xml:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<include
    android:id="@+id/toolbar"
    layout="@layout/toolbar"/>

<FrameLayout
    android:id="@+id/mainFragment"
    android:layout_below="@id/toolbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

TasksFragment xml:

<FrameLayout>
    <android.support.v7.widget.RecyclerView />
</FrameLayout>

TasksAdapter:

public class TasksAdapter extends
    RecyclerView.Adapter<TasksAdapter.ViewHolder> {

static class ViewHolder extends RecyclerView.ViewHolder {
    TextView titleTextView;
    TextView subTitle;
    Button messageButton;
    ImageView taskImage;
    TextView taskDescription;
    CardView cv;

    ViewHolder(View itemView) {
        super(itemView);
        cv = (CardView) itemView.findViewById(R.id.cv);
        titleTextView = (TextView) itemView.findViewById(R.id.task_title);
        subTitle = (TextView) itemView.findViewById(R.id.task_subtitle);
        messageButton = (Button) itemView.findViewById(R.id.message_button);
        taskImage = (ImageView) itemView.findViewById(R.id.task_image);
        taskDescription = (TextView) itemView.findViewById(R.id.task_description);
    }
}

private List<Task> mTasks;
// Store the context for easy access
private Context mContext;
private Fragment fragment;


public TasksAdapter(Context context, List<Task> tasks) {
    mTasks = tasks;
    mContext = context;

}

private Context getContext() {
    return mContext;
}

@Override
public TasksAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    Context context = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(context);

    // Inflate the custom layout
    View taskView = inflater.inflate(R.layout.tasks_item, parent, false);

    // Return a new holder instance
    ViewHolder viewHolder = new ViewHolder(taskView);
    return viewHolder;
}

@Override
public void onBindViewHolder(final TasksAdapter.ViewHolder viewHolder, final int position) {
    // Get the data model based on position
    Task task = mTasks.get(position);

    // Set item views based on views and data model
    TextView textView = viewHolder.titleTextView;
    textView.setText(task.getTitle());
    TextView subTitleTextView = viewHolder.subTitle;
    subTitleTextView.setText(task.getSubTitle());
    ImageView imageView = viewHolder.taskImage;
    imageView.setImageResource(task.getImage());
    TextView taskDescriptionTextView = viewHolder.taskDescription;
    taskDescriptionTextView.setText(task.getDescription());
    Button button = viewHolder.messageButton;
    button.setText(task.getAction());
}

1 个答案:

答案 0 :(得分:0)

通过在MainActivity的s1.db_secid=s2.db_parent中将SELECT s1.db_secname FROM tbl_section AS s1 JOIN tbl_section AS s2 ON s1.db_parent = s2.db_secid WHERE s2.db_parent IS NULL设置为android:layout_height来解决此问题。

像这样:

fill_parent