问题是,当reinlerViewHolder()通过膨胀新项目布局的方法时,recyclerview第一次滚动时会出现新的rv项目出现的时刻。任何加速流程或预先布局的解决方案?因为在创建足够的布局来回收物品时,它会开始顺利滚动。
public class PersonInReviewRvAdapter extends RecyclerView.Adapter<PersonInReviewRvAdapter.PersonHolder> {
private Context context;
private OnItemClickListener itemClickedInterface;
private OnItemLongClickListener itemLongClickedInterface;
public List<SoundingBoardPersonModel> daterList = new ArrayList<>();
public PersonInReviewRvAdapter(Context context, List<SoundingBoardPersonModel> daterList) {
this.context = context;
this.daterList = daterList;
}
@Override
public PersonInReviewRvAdapter.PersonHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View layoutView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_review_match_sb, parent, false);
return new PersonInReviewRvAdapter.PersonHolder(layoutView);
}
@Override
public void onBindViewHolder(PersonInReviewRvAdapter.PersonHolder holder, int position) {
}
public void setItemClickListener(OnItemClickListener itemClickedInterface) {
this.itemClickedInterface = itemClickedInterface;
}
public void setLongItemClickListener(OnItemLongClickListener itemLongClickedInterface) {
this.itemLongClickedInterface = itemLongClickedInterface;
}
public void addContact(String name, String location) {
SoundingBoardPersonModel soundingBoardPersonModel = new SoundingBoardPersonModel();
soundingBoardPersonModel.name = name;
soundingBoardPersonModel.location = location;
daterList.add(soundingBoardPersonModel);
notifyDataSetChanged();
}
public void removeContact(int position) {
daterList.remove(position);
notifyDataSetChanged();
}
@Override
public int getItemCount() {
return 10;
}
static class PersonHolder extends RecyclerView.ViewHolder {
@BindView(R.id.item_container)
RelativeLayout itemContainer;
@BindView(R.id.person_subscriber_name)
TextViewNexaBold nameTxt;
@BindView(R.id.person_subscriber_location)
TextViewNexaLight personLocation;
public PersonHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}}
项目布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_gray_bottom_top_stroke">
<RelativeLayout
android:id="@+id/subscriber_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/size_24dp"
android:layout_marginTop="@dimen/size_24dp"
android:layout_toLeftOf="@+id/center_container">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/person_subscribre_icon"
android:layout_width="@dimen/size_80dp"
android:layout_height="@dimen/size_80dp"
android:layout_centerHorizontal="true" />
<com.qazaqfound.thesetup.custom_views.TextViewNexaBold
android:id="@+id/person_subscriber_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/person_subscribre_icon"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/size_16dp"
android:ellipsize="marquee"
android:maxLines="1"
android:maxWidth="@dimen/size_120dp"
android:text="Melisa"
android:textColor="@color/dark_grey_main"
android:textSize="@dimen/text_size_16sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/person_subscriber_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/size_8dp"
android:orientation="horizontal">
<ImageView
android:layout_width="@dimen/size_16dp"
android:layout_height="@dimen/size_16dp"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_location" />
<com.qazaqfound.thesetup.custom_views.TextViewNexaLight
android:id="@+id/person_subscriber_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/size_2dp"
android:layout_marginTop="@dimen/size_1dp"
android:ellipsize="marquee"
android:maxLines="1"
android:text="USA, New York" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/target_match_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/size_24dp"
android:layout_marginTop="@dimen/size_24dp"
android:layout_toRightOf="@+id/center_container">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/person_match_icon"
android:layout_width="@dimen/size_80dp"
android:layout_height="@dimen/size_80dp"
android:layout_centerHorizontal="true" />
<com.qazaqfound.thesetup.custom_views.TextViewNexaBold
android:id="@+id/person_target_match_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/person_match_icon"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/size_16dp"
android:ellipsize="marquee"
android:maxLines="1"
android:maxWidth="@dimen/size_120dp"
android:text="Melisa"
android:textColor="@color/dark_grey_main"
android:textSize="@dimen/text_size_16sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/person_target_match_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/size_8dp"
android:orientation="horizontal">
<ImageView
android:layout_width="@dimen/size_16dp"
android:layout_height="@dimen/size_16dp"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_location" />
<com.qazaqfound.thesetup.custom_views.TextViewNexaLight
android:id="@+id/ic_location_match"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/size_2dp"
android:layout_marginTop="@dimen/size_1dp"
android:ellipsize="marquee"
android:maxLines="1"
android:text="USA, New York" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/center_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/size_36dp"
android:orientation="vertical">
<ImageView
android:id="@+id/ic"
android:layout_width="@dimen/size_40dp"
android:layout_height="@dimen/size_40dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/ic_match_arrow" />
<com.qazaqfound.thesetup.custom_views.TextViewNexaBold
android:id="@+id/time_remaining_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/size_8dp"
android:text="20 minutes"
android:textColor="@color/dark_pink" />
<com.qazaqfound.thesetup.custom_views.TextViewNexaBold
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/size_8dp"
android:text="@string/text_remaining" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/subscriber_container"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/size_16dp">
<ImageView
android:id="@+id/like_btn"
android:layout_width="@dimen/size_70dp"
android:layout_height="@dimen/size_70dp"
android:src="@drawable/ic_like" />
<ImageView
android:id="@+id/dislike_btn"
android:layout_width="@dimen/size_70dp"
android:layout_height="@dimen/size_70dp"
android:layout_toRightOf="@+id/like_btn"
android:src="@drawable/ic_dislike" />
</RelativeLayout>
答案 0 :(得分:0)
我注意到您使用了<com.qazaqfound.thesetup.custom_views.TextViewNexaBold>
个自定义视图。我使用相同的方法用自定义字体创建TextView。如果是这样,请避免从资产文件夹中删除字体。