很早之前做过一个商城的app 也是第一次做安卓。
实现的效果如下:
因为一开始做安卓,很多写的代码都不规范,在下面上代码的地方,还请高手指点(勿喷,楼主是自尊心很强的屌丝)
这个效果要解决2个大问题,
第一个是ExpandableListView 如何放置gridview ,这个比较好做 思路就是adapter里实现
第二个是在ExpandableListView里面展开后,GirdView如何能充满ExpandableListView的item, 就是楼上的效果
好,先来解决第一个。如何放置gridview,
在这里使用的adapter 是BaseExpandableListAdapter 并且实现点击girdview里面item的事件
//适配器 class madapter extends BaseExpandableListAdapter implements OnItemClickListener { @Override public int getGroupCount() { // TODO Auto-generated method stub return alllist.size(); } @Override public int getChildrenCount(int groupPosition) { return 1; } @Override public Object getGroup(int groupPosition) { // TODO Auto-generated method stub return alllist.get(groupPosition).parentnode; } @Override public Object getChild(int groupPosition, int childPosition) { // TODO Auto-generated method stub return null; } @Override public long getGroupId(int groupPosition) { // TODO Auto-generated method stub return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { // TODO Auto-generated method stub return childPosition; } @Override public boolean hasStableIds() { // TODO Auto-generated method stub return true; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { TextView text = createView(getGroup(groupPosition).toString(),getContext()); return text; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { layoutInflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); ViewGroup item = (ViewGroup)layoutInflater.inflate(R.layout.shops_allshops_type_grid, null); //载入gridview布局 grid = (ShowAllShopsType_list_grid) item.findViewById(R.id.shopstypegridview);// 获取girdview的节点 grid.setNumColumns(4);// 设置每行列数 grid.setGravity(Gravity.CENTER);// 位置居中 grid.setVerticalSpacing(10); grid.setAdapter(gridAdapter(parent.getContext(),(int)getGroupId(groupPosition))); grid.setOnItemClickListener(this); grid.setVisibility(View.VISIBLE); return item; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { // TODO Auto-generated method stub return true; } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent =new Intent(getContext(),ShowAllShops.class); intent.putExtra("text", ((TextView)view).getText()); //getContext().startActivity(intent); shopactivty.setResult(1, intent); shopactivty.finish(); } }
代码只是提供思路的,详细的哪里不懂可以评论发
第二个问题是gridview的自适应
public class ShowAllShopsType_list_grid extends GridView{ public ShowAllShopsType_list_grid(Context context, AttributeSet attrs) { super(context, attrs); } /** * 设置不滚动 */ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); }
这里只是重写了onMeasure 方法,这样的重写 在ScrollView里放置ListView的冲突上面一样可以解决。
相关推荐
ExpandableListView嵌套GridView的实现,
ExpandableListView嵌套GridView的实现,并且手动自定义gridview已适应expandableListView
1.ExpandableListView 嵌套gridView ,在 gridView里处理点击事件 2.group中自己可以自定义文字和图片,本例中定义文字
ExpandableListView 中完美嵌套 GridView
android中ExpandableListView嵌套GridView的使用
安卓ExpandableListView嵌套Gridview嵌套用法,与多点触控图片缩放。代码写的交简单。数据少,但有代表性。
ExpandableListView嵌套GridView,GridView中的item带有选中功能
1、ExpandableListView嵌套GridView 2、group中自定义文字和图片 原文章在 http://blog.csdn.net/u011123829/article/details/9278351
Android ExpandableListView双层嵌套实现三级树形菜单
android中ExpandableListView嵌套ListView和GridView的使用
treeView Android ExpandableListView双层嵌套实现三级树形菜单
第一次遇见这样子的嵌套,有点晕,用了一上午时间,总算搞定,这个demo主要是ExpandableListView下的Item嵌套使用时间轴,另可以实现点击事件
ExpandableListView (实现ListView嵌套ListView的效果)
ExpandableListView嵌套GridView 实现多标题
我看到很多 是ExpandableListView嵌套gridview。 但很多人不需要ExpandableListView 只是单纯的ListView 因此 随意写了一份 给大家借鉴。
ExpandableListView,recyclerview和listview的使用
自定义ListView内嵌GridView,用ExpandableListView实现,教你如何实现多级菜单的设计
基于expandablelistview + gridview + 手势的新闻客户端
ExpandableListView实现购物车页面