小编Vis*_* M.的帖子

如何在初始化适配器时按顺序为RecyclerView项设置动画(按顺序)?

我正在努力实现的目标

我想在线性垂直RecyclerView中按顺序显示项目.我希望第一个项目出现,然后是第二个项目,然后是第三个项目,依此类推.这是我想要完成的动画类型的一个例子.

动画示例


我试过的

我已经尝试了这个问题中提供的方法:如何在RecyclerView项目出现时为其设置动画

但是,这并不是我想要完成的.这会导致RecyclerView中的所有项目一次出现,而不是一次出现一次.


我的代码

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

    private int lastPosition = -1;

    //constructor and other code not shown...

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        switch (viewHolder.getItemViewType()) {
            case OP:
                OPViewHolder ovh = (OPViewHolder) viewHolder;
                configureOPViewHolder(ovh, position);
                setAnimation(ovh.getContainer(), position);
                break;
            case COMMENT:
                CommentViewHolder cvh = (CommentViewHolder) viewHolder;
                configureCommentViewHolder(cvh, position);
                setAnimation(cvh.getContainer(), position);
                break;
            default:
                RecyclerViewSimpleTextViewHolder vh = (RecyclerViewSimpleTextViewHolder) viewHolder;
                configureDefaultViewHolder(vh, position);
                break;
        }

    }

    @Override
    public void onViewDetachedFromWindow(final RecyclerView.ViewHolder viewHolder)
    {

        switch (viewHolder.getItemViewType()) { …
Run Code Online (Sandbox Code Playgroud)

android

12
推荐指数
2
解决办法
8871
查看次数

如何在ConstraintLayout中水平对齐两个TextView而不重叠?

我试图像这样水平对齐两个 TextView: 文本 A 简短正确 当文本 A 很短时,我当前的布局工作正常。但是,当为 textA 设置长字符串时,事情会中断,如下所示。即使文本 A 的结尾被限制在文本 B 的开头,文本 A 和文本 B 也会重叠。 文本 A 长重叠

这是文本 A 很长时的外观。 文本 A 长正确


当前的 XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="8dp">

    <TextView
        android:id="@+id/textA"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/rounded_gray_background"
        android:ellipsize="end"
        android:lines="1"
        android:padding="4dp"
        android:text="Text A"
        app:layout_constraintEnd_toStartOf="@id/textB"
        app:layout_constraintHorizontal_bias="0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="4dp"
        android:text="Text B"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

android android-constraintlayout

7
推荐指数
1
解决办法
2903
查看次数

标签 统计

android ×2

android-constraintlayout ×1