From b608de9aa8a5dfd2de88d8ef6dd39a2db20aefd9 Mon Sep 17 00:00:00 2001 From: chaychan <844738237@qq.com> Date: Fri, 23 Jun 2017 13:58:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=90=E6=9D=A1=E7=9B=AE?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E7=9A=84=E5=9B=9E=E8=B0=83=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=BD=93=E5=89=8D=E5=AD=90=E6=9D=A1?= =?UTF-8?q?=E7=9B=AE=E7=9A=84=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bottombarlayout/BottomBarLayout.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/viewlib/src/main/java/com/chaychan/viewlib/bottombarlayout/BottomBarLayout.java b/viewlib/src/main/java/com/chaychan/viewlib/bottombarlayout/BottomBarLayout.java index c0a6aca..2ab5724 100644 --- a/viewlib/src/main/java/com/chaychan/viewlib/bottombarlayout/BottomBarLayout.java +++ b/viewlib/src/main/java/com/chaychan/viewlib/bottombarlayout/BottomBarLayout.java @@ -24,7 +24,7 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha private ViewPager mViewPager; private int mChildCount;//子条目个数 - private List itemViews = new ArrayList<>(); + private List mItemViews = new ArrayList<>(); private int mCurrentItem;//当前条目的索引 private boolean mSmoothScroll; @@ -67,7 +67,7 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha for (int i = 0; i < mChildCount; i++) { if (getChildAt(i) instanceof BottomBarItem) { BottomBarItem bottomBarItem = (BottomBarItem) getChildAt(i); - itemViews.add(bottomBarItem); + mItemViews.add(bottomBarItem); //设置点击监听 bottomBarItem.setOnClickListener(new MyOnClickListener(i)); } else { @@ -75,7 +75,7 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha } } - itemViews.get(mCurrentItem).setStatus(true);//设置选中项 + mItemViews.get(mCurrentItem).setStatus(true);//设置选中项 mViewPager.setOnPageChangeListener(this); } @@ -88,7 +88,7 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha public void onPageSelected(int position) { mCurrentItem = position;//记录当前位置 resetState(); - itemViews.get(position).setStatus(true); + mItemViews.get(position).setStatus(true); mViewPager.setCurrentItem(position, mSmoothScroll); } @@ -109,12 +109,12 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha public void onClick(View v) { //回调点击的位置 if (onItemSelectedListener != null) { - onItemSelectedListener.onItemSelected(currentIndex); + onItemSelectedListener.onItemSelected(getBottomItem(currentIndex),currentIndex); } //点击前先重置所有按钮的状态 resetState(); - itemViews.get(currentIndex).setStatus(true);//设置为选中状态 + mItemViews.get(currentIndex).setStatus(true);//设置为选中状态 //不能使用平滑滚动,否者颜色改变会乱 mViewPager.setCurrentItem(currentIndex, false); //点击是保存当前按钮索引 @@ -127,7 +127,7 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha */ private void resetState() { for (int i = 0; i < mChildCount; i++) { - itemViews.get(i).setStatus(false); + mItemViews.get(i).setStatus(false); } } @@ -144,6 +144,10 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha this.mSmoothScroll = mSmoothScroll; } + public BottomBarItem getBottomItem(int position){ + return mItemViews.get(position); + } + /** * @return 当View被销毁的时候,保存数据 */ @@ -166,7 +170,7 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha //重置所有按钮状态 resetState(); //恢复点击的条目颜色 - itemViews.get(mCurrentItem).setStatus(true); + mItemViews.get(mCurrentItem).setStatus(true); super.onRestoreInstanceState(bundle.getParcelable(STATE_INSTANCE)); } else { super.onRestoreInstanceState(state); @@ -176,7 +180,7 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha private OnItemSelectedListener onItemSelectedListener; public interface OnItemSelectedListener { - void onItemSelected(int position); + void onItemSelected(BottomBarItem bottomBarItem,int position); } public void setOnItemSelectedListener(OnItemSelectedListener onItemSelectedListener) { -- GitLab