Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChayChan
ExpandableLinearLayout
提交
ac784094
E
ExpandableLinearLayout
项目概览
ChayChan
/
ExpandableLinearLayout
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
5
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
ExpandableLinearLayout
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
5
Issue
5
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ac784094
编写于
7月 22, 2017
作者:
C
chaychan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.修复使用默认底部状态下,条目插入顺序混乱的Bug;2.增加子条目点击事件的监听
上级
93fe4605
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
54 addition
and
9 deletion
+54
-9
README.md
README.md
+9
-0
demo/src/main/java/com/chaychan/expandablelinearlayout/EllCustomBottomDemoActivity.java
...n/expandablelinearlayout/EllCustomBottomDemoActivity.java
+9
-2
demo/src/main/java/com/chaychan/expandablelinearlayout/EllDefaultBottomDemoActivity.java
.../expandablelinearlayout/EllDefaultBottomDemoActivity.java
+8
-0
demo/src/main/res/layout/page_ell_custom_bottom_demo.xml
demo/src/main/res/layout/page_ell_custom_bottom_demo.xml
+1
-1
library/src/main/java/com/chaychan/library/ExpandableLinearLayout.java
...ain/java/com/chaychan/library/ExpandableLinearLayout.java
+27
-6
未找到文件。
README.md
浏览文件 @
ac784094
...
...
@@ -114,6 +114,15 @@
![](
./intro_img/ell_4.gif
)
#### 5.设置条目点击事件
ellProduct.setOnItemClickListener(new ExpandableLinearLayout.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Toast.makeText(EllCustomBottomDemoActivity.this,names[position] , Toast.LENGTH_SHORT).show();
}
});
### 二、使用自定义底部
布局文件中,ExpandableLinearLayout配置useDefaultBottom="false",声明不使用默认底部。自己定义底部的布局。
...
...
demo/src/main/java/com/chaychan/expandablelinearlayout/EllCustomBottomDemoActivity.java
浏览文件 @
ac784094
...
...
@@ -6,6 +6,7 @@ import android.view.View;
import
android.widget.ImageView
;
import
android.widget.RelativeLayout
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.bumptech.glide.Glide
;
import
com.chaychan.expandablelinearlayout.bean.ProductBean
;
...
...
@@ -62,7 +63,7 @@ public class EllCustomBottomDemoActivity extends AppCompatActivity {
ellProduct
.
removeAllViews
();
//清除所有的子View(避免重新刷新数据时重复添加)
//添加数据
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
View
view
=
View
.
inflate
(
this
,
R
.
layout
.
item_product
,
null
);
ProductBean
productBean
=
new
ProductBean
(
imgUrls
[
i
],
names
[
i
],
intros
[
i
],
"12.00"
);
ViewHolder
viewHolder
=
new
ViewHolder
(
view
,
productBean
);
...
...
@@ -90,6 +91,13 @@ public class EllCustomBottomDemoActivity extends AppCompatActivity {
ellProduct
.
toggle
();
}
});
ellProduct
.
setOnItemClickListener
(
new
ExpandableLinearLayout
.
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
View
view
,
int
position
)
{
Toast
.
makeText
(
EllCustomBottomDemoActivity
.
this
,
names
[
position
]
,
Toast
.
LENGTH_SHORT
).
show
();
}
});
}
// 箭头的动画
...
...
@@ -103,7 +111,6 @@ public class EllCustomBottomDemoActivity extends AppCompatActivity {
}
}
class
ViewHolder
{
@Bind
(
R
.
id
.
iv_img
)
ImageView
ivImg
;
...
...
demo/src/main/java/com/chaychan/expandablelinearlayout/EllDefaultBottomDemoActivity.java
浏览文件 @
ac784094
...
...
@@ -5,6 +5,7 @@ import android.support.v7.app.AppCompatActivity;
import
android.view.View
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.bumptech.glide.Glide
;
import
com.chaychan.expandablelinearlayout.bean.ProductBean
;
...
...
@@ -60,6 +61,13 @@ public class EllDefaultBottomDemoActivity extends AppCompatActivity {
viewHolder
.
refreshUI
();
ellProduct
.
addItem
(
view
);
//添加子条目
}
ellProduct
.
setOnItemClickListener
(
new
ExpandableLinearLayout
.
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
View
view
,
int
position
)
{
Toast
.
makeText
(
EllDefaultBottomDemoActivity
.
this
,
names
[
position
]
,
Toast
.
LENGTH_SHORT
).
show
();
}
});
}
class
ViewHolder
{
...
...
demo/src/main/res/layout/page_ell_custom_bottom_demo.xml
浏览文件 @
ac784094
...
...
@@ -19,7 +19,7 @@
android:layout_height=
"wrap_content"
android:layout_marginTop=
"10dp"
android:orientation=
"vertical"
app:defaultItemCount=
"
2
"
app:defaultItemCount=
"
3
"
app:useDefaultBottom=
"false"
>
...
...
library/src/main/java/com/chaychan/library/ExpandableLinearLayout.java
浏览文件 @
ac784094
...
...
@@ -34,6 +34,7 @@ public class ExpandableLinearLayout extends LinearLayout implements View.OnClick
private
float
fontSize
;
private
int
textColor
;
private
int
arrowResId
;
private
int
mPosition
;
public
ExpandableLinearLayout
(
Context
context
)
{
this
(
context
,
null
);
...
...
@@ -85,10 +86,10 @@ public class ExpandableLinearLayout extends LinearLayout implements View.OnClick
public
void
addItem
(
View
view
)
{
int
childCount
=
getChildCount
();
if
(!
useDefaultBottom
){
//如果不使用默认底部
addView
(
view
);
int
childCount
=
getChildCount
();
if
(
childCount
>
defaultItemCount
){
hide
();
}
...
...
@@ -100,7 +101,8 @@ public class ExpandableLinearLayout extends LinearLayout implements View.OnClick
//如果还没有底部
addView
(
view
);
}
else
{
addView
(
view
,
childCount
-
2
);
//插在底部之前
int
childCount
=
getChildCount
();
addView
(
view
,
childCount
-
1
);
//插在底部之前
}
refreshUI
(
view
);
}
...
...
@@ -205,13 +207,13 @@ public class ExpandableLinearLayout extends LinearLayout implements View.OnClick
isExpand
=
!
isExpand
;
//回调
if
(
mListener
!=
null
){
mListener
.
onStateChanged
(
isExpand
);
if
(
m
State
Listener
!=
null
){
m
State
Listener
.
onStateChanged
(
isExpand
);
}
}
private
OnStateChangeListener
mListener
;
private
OnStateChangeListener
m
State
Listener
;
/**
* 定义状态改变接口
...
...
@@ -221,6 +223,25 @@ public class ExpandableLinearLayout extends LinearLayout implements View.OnClick
}
public
void
setOnStateChangeListener
(
OnStateChangeListener
mListener
)
{
this
.
mListener
=
mListener
;
this
.
mStateListener
=
mListener
;
}
public
void
setOnItemClickListener
(
final
OnItemClickListener
listener
){
int
endIndex
=
useDefaultBottom
?
getChildCount
()
-
1
:
getChildCount
();
//如果是使用默认底部,则结束的下标是到底部之前
for
(
int
i
=
0
;
i
<
endIndex
;
i
++){
View
view
=
getChildAt
(
i
);
final
int
position
=
i
;
view
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
listener
.
onItemClick
(
v
,
position
);
}
});
}
}
public
interface
OnItemClickListener
{
void
onItemClick
(
View
view
,
int
position
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录