最近需求sama联合美工娘娘又改了界面,整体的界面是华丽了不少,但是大神何必为难弱智儿童的我呢,下面先看看新界面~
很经典的菜单设计,不过毕竟是版本更迭,不适合在原有基础上大修改改,菜单总共分了4个父菜单和若干个子菜单,点击父菜单会隐藏子菜单,其中还要有收起展开动画,这个首先令我想起了expanedlistview。说动手就动手,花了几分钟先写个demo测试以下吧。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/exlistview"
></ExpandableListView>
</RelativeLayout>
这个很简单的布局代码,不必多说了~
然后定义一个实体类,包含父子菜单所必需的内容
public class Bean {
public Bean(String title, List<childBean> childBeans) {
this.title = title;
this.childBeans = childBeans;
}
public Bean() {
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<childBean> getChildBeans() {
return childBeans;
}
public void setChildBeans(List<childBean> childBeans) {
this.childBeans = childBeans;
}
private String title;
private List<childBean> childBeans;
public static class childBean{
private String title;
public childBean(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
}
这几行代码也不必多说,一目了然,如果需要添加其他的 自然也可以自己添加~
最后开始写自定义adapter了,也很简单不是吗?
public class TestAdapter extends BaseExpandableListAdapter {
private List<Bean> groups;
private Context context;
public TestAdapter( Context context, List<Bean> groups){
this.context=context;
this.groups=groups;
}
@Override
public int getGroupCount() {
return groups.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return groups.get(groupPosition).getChildBeans().size();
}
@Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
@Override