AndroidKun / XTabLayout

Added support to modify text size and indicator width based on the original TabLayout.
666 stars 109 forks source link

viewPager.setCurrentItem(position); tablayout中的tab 不是在屏幕中间 有时会在屏幕外 #29

Closed XuEnhao closed 6 years ago

XuEnhao commented 6 years ago

tabLayout.setScrollPosition(0,tabLayout.getSelectedTabPosition(),true); 找到了这个方法 但是好像没什么用

AndroidKun commented 6 years ago

参数是不是传错了,第一个是滚动到的目标Tab的下标,第二个是偏移量

XuEnhao commented 6 years ago

tabLayout.setupWithViewPager(viewPager); tabLayout.setScrollPosition(position,position,true); viewPager.setCurrentItem(position); 还是没有显示在屏幕中

XuEnhao commented 6 years ago

tabLayout.getSelectedTabPosition():这个位置是正确的 但是就是没有滚动到屏幕中间

XuEnhao commented 6 years ago

总数是14个 在34567的时候 会缓缓偏移出屏幕 在后边整个就没了

AndroidKun commented 6 years ago

第二个参数传0

XuEnhao commented 6 years ago

final int roundedPosition = Math.round(position + positionOffset); if (roundedPosition < 0 || roundedPosition >= mTabStrip.getChildCount()) { return; } 我看源码 我如果点击的是最后一个 因为他是大于等于 childcount 直接return掉了?

AndroidKun commented 6 years ago

那肯定return了,没有找到对应Position的Tab

XuEnhao commented 6 years ago

总数15 在我点击第7个时已经跑出屏幕外了

XuEnhao commented 6 years ago

看下您的网易邮箱 发邮件了 能详细说下吗

AndroidKun commented 6 years ago

我测试过是没问题的 你再检查一下参数是否正确吧

XuEnhao commented 6 years ago

我不做操作 直接viewpager.setcurritem 在第7个的时候就已经不在屏幕内了 title比较长

XuEnhao commented 6 years ago

我看demo中 什么操作都没有做

XuEnhao commented 6 years ago

进页面的时候 就直接setcurrtitem 数值越大偏移的越多 然后就出现了 偏移屏幕的问题

XuEnhao commented 6 years ago

还是用的原生解决的 偏移问题