Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChayChan
PowerfulViewLibrary
提交
b608de9a
P
PowerfulViewLibrary
项目概览
ChayChan
/
PowerfulViewLibrary
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
6
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PowerfulViewLibrary
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
6
Issue
6
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b608de9a
编写于
6月 23, 2017
作者:
C
chaychan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改子条目点击的回调方法,增加当前子条目的返回
上级
1901c037
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
13 addition
and
9 deletion
+13
-9
viewlib/src/main/java/com/chaychan/viewlib/bottombarlayout/BottomBarLayout.java
...com/chaychan/viewlib/bottombarlayout/BottomBarLayout.java
+13
-9
未找到文件。
viewlib/src/main/java/com/chaychan/viewlib/bottombarlayout/BottomBarLayout.java
浏览文件 @
b608de9a
...
...
@@ -24,7 +24,7 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha
private
ViewPager
mViewPager
;
private
int
mChildCount
;
//子条目个数
private
List
<
BottomBarItem
>
i
temViews
=
new
ArrayList
<>();
private
List
<
BottomBarItem
>
mI
temViews
=
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
);
i
temViews
.
add
(
bottomBarItem
);
mI
temViews
.
add
(
bottomBarItem
);
//设置点击监听
bottomBarItem
.
setOnClickListener
(
new
MyOnClickListener
(
i
));
}
else
{
...
...
@@ -75,7 +75,7 @@ public class BottomBarLayout extends LinearLayout implements ViewPager.OnPageCha
}
}
i
temViews
.
get
(
mCurrentItem
).
setStatus
(
true
);
//设置选中项
mI
temViews
.
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
();
i
temViews
.
get
(
position
).
setStatus
(
true
);
mI
temViews
.
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
();
i
temViews
.
get
(
currentIndex
).
setStatus
(
true
);
//设置为选中状态
mI
temViews
.
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
++)
{
i
temViews
.
get
(
i
).
setStatus
(
false
);
mI
temViews
.
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
();
//恢复点击的条目颜色
i
temViews
.
get
(
mCurrentItem
).
setStatus
(
true
);
mI
temViews
.
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
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录