saiwu-bigkoo / Android-ConvenientBanner

Simple and convenient banner, loop viewpager with 3D effects
4.77k stars 1.06k forks source link

ItemView宽度为0的问题 #355

Open androidWht opened 4 years ago

androidWht commented 4 years ago

image image

liuan3756 commented 3 years ago

我直接new一个ConvenientBanner,然后addview到布局中也是会这样,item的宽度都是0,但是高度有值。如果直接在xml中写的话就不会。

liuan3756 commented 3 years ago
 convenientBanner.setPages(new CBViewHolderCreator()
        {
            @Override
            public ImageHolderView createHolder(View itemView)
            {
                ViewGroup.LayoutParams layoutParams = itemView.getLayoutParams();
                layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
                return new ImageHolderView(itemView);
            }

            @Override
            public int getLayoutId()
            {
                return R.layout.item_banner;
            }
        }, strings);

这样我试了是可以的 宽度正常了