我将 PagerAdapter 用于 ViewPager Adapter,没有任何片段,只有一个选项卡布局,这很好,我可以把我的数据和......但我有一个滑动问题......它是颠倒的......我想要正确的向左但从左向右滑动...
ViewPagerAdapter.java
public class ViewPagerAdapter extends PagerAdapter {
private static final String TAG = "ViewPagerAdapter";
private Context context;
private List<PersonItem> personItemList;
public ViewPagerAdapter(Context context, List<PersonItem> personItemList) {
this.context = context;
this.personItemList = personItemList;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
@Override
public int getCount() {
return personItemList.size();
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return personItemList.get(position).getTabTitle();
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
LayoutInflater inflater = LayoutInflater.from(context);
ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.fragment_layout, container, false);
PersonItem personItem = personItemList.get(position);
ImageView imgPerson = layout.findViewById(R.id.img_person);
TextView txtPersonContent = layout.findViewById(R.id.txt_person_content);
if (personItem.getImageUrl() != null) {
Glide.with(context)
.load(personItem.getImageUrl())
.into(imgPerson);
} else {
imgPerson.setVisibility(View.GONE);
}
if (personItem.getContent() != null) {
txtPersonContent.setText(personItem.getContent());
}
container.addView(layout);
return layout;
}
ibeautiful
holdtom
相关分类