我正在努力实现的目标
我想在线性垂直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) 我试图像这样水平对齐两个 TextView:
当文本 A 很短时,我当前的布局工作正常。但是,当为 textA 设置长字符串时,事情会中断,如下所示。即使文本 A 的结尾被限制在文本 B 的开头,文本 A 和文本 B 也会重叠。

当前的 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)