Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

banner画廊模式 #1241

Open
qiongqiong-wu opened this issue Sep 13, 2024 · 5 comments
Open

banner画廊模式 #1241

qiongqiong-wu opened this issue Sep 13, 2024 · 5 comments

Comments

@qiongqiong-wu
Copy link

banner画廊模式可以显示两边各2张图片吗

@chenxinfeng0406
Copy link

设置每页的宽度就行

@qiongqiong-wu
Copy link
Author

banner.setBannerGalleryEffect(50, 10);仅仅只能设置两边各一张图,你说的“设置每页的宽度就行”要如何实现呢?目前有具体的实现方法吗?

@Doublelsl
Copy link

banner.setBannerGalleryEffect(50, 10);仅仅只能设置两边各一张图,你说的“设置每页的宽度就行”要如何实现呢?目前有具体的实现方法吗?

我实现了两端各两张图,实现方法如下:
前提:图的总数不少于2张
1.StartPosition要设置为2
2.添加addOnPageChangeListener,onPageSelected中获取当前position,可已直复制Banner中,position是真实位置
3.onPageScrollStateChanged中滑动完成时,根据自己需要添加的图片数量自行实现重新定位,已两端两张为例,位置为0时,定位到getItemCount() - 3,位置为getItemCount() - 3时定位到2
4.自定义adapter,重写onBindViewHolder,参照BannerAdapter,保留
int real = getRealPosition(position);
onBindView(holder, mDatas.get(real), real, getRealCount());
if (mOnBannerListener != null)
holder.itemView.setOnClickListener(view -> mOnBannerListener.OnBannerClick(mDatas.get(real), real));
5.自定义adapter中实现getRealPosition,getRealPosition中的逻辑为将原有list中数据的最后两条放到最前方,头两条放在最后放,实现首尾相接。
6.getItemCount中根据自己的需求返回list.size() + 第5步添加的条数,比如我是在list.size()>1时添加4条

@Doublelsl
Copy link

banner.setBannerGalleryEffect(50, 10);仅仅只能设置两边各一张图,你说的“设置每页的宽度就行”要如何实现呢?目前有具体的实现方法吗?

补充设置宽度的问题,第一个参数设置大一些,具体多少自行适配,比如宽度可设置为(屏幕宽度 - banner到屏幕的间距 - 图片间距 - 一个图的宽度)/ 2

@qiongqiong-wu
Copy link
Author

折叠屏幕 屏幕折叠撑起会出现banner画廊效果错位,请问有解决方法吗
if (!isFoldableDeviceOpened) {
marginWidth = dp2px(15f)
leftItemWidth = dp2px(60f)
cardBannerAdapter?.setFoldableDevice(true)
} else {
marginWidth = dp2px(5f)
leftItemWidth = dp2px(10f)
cardBannerAdapter?.setFoldableDevice(false)
}

    mBinding.homeBanner.setBannerGalleryEffect(
        leftItemWidth,
        leftItemWidth,
        marginWidth,
        0.85f
    )
    cardBannerAdapter?.notifyDataSetChanged()
    mBinding.homeBanner.post {
        mBinding.homeBanner.viewPager2.requestTransform()
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants