scrollview gridview
package com.fangdamai.salewinner.ui.customer;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.TextView;
import com.fangdamai.salewinner.R;
import com.fangdamai.salewinner.ui.base.BaseActivity;
import com.fangdamai.salewinner.utils.LogUtil;
import com.fangdamai.salewinner.widget.MyGridView;
public class CustomerEditActivity extends BaseActivity {
ExpandableListView expandListview;
int[] childHeight = new int[7];
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_customer_edit);
getSupportActionBar().setTitle("基本信息编辑");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
expandListview = (ExpandableListView) findViewById(R.id.expandableListView1);
MyExpandListAdapter adapter = new MyExpandListAdapter(mContext);
expandListview.setAdapter(adapter);
setExpandableListViewHeight();
expandListview
.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int arg0) {
ViewGroup.LayoutParams params = expandListview
.getLayoutParams();
int orignHeigth = params.height;
// 获取将要展开的子view的高度
int gridviewHeight = childHeight[arg0];
LogUtil.i("oh:" + orignHeigth + " gh:"
+ gridviewHeight);
params.height = orignHeigth - gridviewHeight;
expandListview.setLayoutParams(params);
expandListview.requestLayout();
}
});
expandListview.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int arg0) {
ViewGroup.LayoutParams params = expandListview
.getLayoutParams();
int orignHeigth = params.height;
// 获取将要展开的子view的高度
int gridviewHeight = childHeight[arg0];
LogUtil.i("oh:" + orignHeigth + " gh:"
+ gridviewHeight);
params.height = orignHeigth + gridviewHeight;
expandListview.setLayoutParams(params);
expandListview.requestLayout();
}
});
// for (int i = 0; i < adapter.getGroupCount(); i++) {
// expandListview.expandGroup(i);
// }
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
private void setExpandableListViewHeight() {
ListAdapter listAdapter = expandListview.getAdapter();
int totalHeight = 0;
LogUtil.i("count:" + listAdapter.getCount());
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, expandListview);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
LogUtil.i("height:" + totalHeight);
}
ViewGroup.LayoutParams params = expandListview.getLayoutParams();
params.height = totalHeight
+ (expandListview.getDividerHeight() * (listAdapter.getCount() - 1));
LogUtil.i("exheight:" +params.height);
expandListview.setLayoutParams(params);
expandListview.requestLayout();
}
private int getGridViewHeight(GridView gv) {
ListAdapter listAdapter = gv.getAdapter();
int totalHeight = 0;
LogUtil.i("count:" + listAdapter.getCount());
int count = listAdapter.getCount();
int columns = gv.getNumColumns();
int rows = count / columns + count % columns == 0 ? 0 : 1;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, gv);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
LogUtil.i("height:" + totalHeight);
}
int height = totalHeight + (gv.getVerticalSpacing() * (rows - 1));
return height;
}
private void setGridViewHeight(GridView gridview, int height) {
ViewGroup.LayoutParams params = gridview.getLayoutParams();
params.height = height;
gridview.setLayoutParams(params);
gridview.requestLayout();
}
class MyExpandListAdapter extends BaseExpandableListAdapter {
private Context context;
private String[] groups = { "购房区域", "购房面积", "房源户型/类型", "购房预算", "置业动机",
"急迫程度", "能否决策" };
private String[][] childs = {
{ "不 限", "园区", "新区", "相城区", "姑苏区", "吴中区" },
getResources().getStringArray(R.array.buid_area),
getResources().getStringArray(R.array.buid_type_room),
getResources().getStringArray(R.array.buy_budget),
getResources().getStringArray(R.array.buy_reason),
getResources().getStringArray(R.array.urgent_degree),
getResources().getStringArray(R.array.canconfirm) };
public MyExpandListAdapter(Context context) {
this.context = context;
}
@Override
public Object getChild(int arg0, int arg1) {
return null;
}
@Override
public long getChildId(int arg0, int arg1) {
return 0;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(context).inflate(
R.layout.item_section_content, null);
GridView gridview = (GridView) convertView
.findViewById(R.id.gridView1);
gridview.setAdapter(new MyGridviewAdatper(childs[groupPosition]));
int height = getGridViewHeight(gridview);
childHeight[groupPosition] = height;
LogUtil.i("position:" + groupPosition + " h:" + height);
setGridViewHeight(gridview, height);
return convertView;
}
@Override
public int getChildrenCount(int arg0) {
return 1;
}
@Override
public Object getGroup(int arg0) {
return groups[arg0];
}
@Override
public int getGroupCount() {
return groups.length;
}
@Override
public long getGroupId(int arg0) {
return 0;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(context).inflate(
R.layout.item_section_header, null);
TextView txtContent = (TextView) convertView
.findViewById(R.id.txt_header);
txtContent.setText(getGroup(groupPosition).toString());
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int arg0, int arg1) {
return false;
}
}
class MyGridviewAdatper extends BaseAdapter {
private String[] items;
public MyGridviewAdatper(String[] items) {
this.items = items;
}
@Override
public int getCount() {
return items.length;
}
@Override
public Object getItem(int arg0) {
return items[arg0];
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(CustomerEditActivity.this)
.inflate(R.layout.item_grid_content, null);
Button txtContent = (Button) convertView.findViewById(R.id.button1);
txtContent.setText(getItem(position).toString());
return convertView;
}
}
}
scrollview gridview的更多相关文章
- 【Android】ScrollView+GridView 显示问题
在使用Android的ScrollView里面嵌套GridView时,设置android:layout_height="wrap_content"属性,运行界面的效果不会出现全部数 ...
- 取消安卓listview,scrollview,gridview滑动时候边缘模糊问题
只需在xml文件里面声明: android:faddingEdge = "none" android:faddingEdgelenth = "0dp" andr ...
- Android 用ListView实现GridView分列显示
我想实现百度影音首页的这种效果: 在网上用ScrollView+GridView可以实现,但是touch scrollview的时候会莫名刷新gridview,这样用户体验很不好,而且感觉百度不是这样 ...
- ## GridView 布局:item设置的高度和宽度不起作用、自动适配列数、添加Header和Footer ##
一.item设置的高度和宽度不起作用 转自:http://www.cnblogs.com/0616--ataozhijia/p/6031875.html [Android Pro] listView和 ...
- 自定义两行可左右滑动的GridView
效果图: xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
- 《安卓网络编程》之第六篇 Android中的WIFI和蓝牙
关于WIFI就不多介绍啦,直接来个段子吧. 问:“WiFi对人体有伤害么?” 答:“不清楚,反正没有WiFi我就浑身不舒服. 比较重要的一点就是WifiManager wm=(WifiManager ...
- wesome-android
awesome-android Introduction android libs from github System requirements Android Notice If the lib ...
- 【朝花夕拾】Android自定义View篇之(七)Android事件分发机制(下)滑动冲突解决方案总结
前言 转载请声明,转自[https://www.cnblogs.com/andy-songwei/p/11072989.html],谢谢! 前面两篇文章,花了很大篇幅讲解了Android的事件分发机制 ...
- ScrollView嵌套ListView,GridView数据加载不全问题的解决
我们大家都知道ListView,GridView加载数据项,如果数据项过多时,就会显示滚动条.ScrollView组件里面只能包含一个组件,当ScrollView里面嵌套listView,GridVi ...
随机推荐
- python 条件判断 if
条件判断 if 格式-1 if 判断条件: 执行语句... num = 10 if num == 4: print("num 等于4") 执行: C:\Python27\pytho ...
- 使用p6spy格式化日志输出
P6Spy 是针对数据库访问操作的动态监测框架(为开源项目,项目首 页:www.p6spy.com)它使得数据库数据可无缝截取和操纵,而不必对现有应用程序的代码作任何修改.P6Spy 分发包包括P6L ...
- Codeforces Gym101473 E.Dangerous Dive (2013-2014 ACM-ICPC Brazil Subregional Programming Contest)
代码: 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cmat ...
- Tallest Cow
题目描述 FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a p ...
- SecureCRT双击Tab快速复制Session
- weblogic控制台登录很慢
分类: Oracle 原文地址:weblogic控制台登录很慢 作者:paomananshan 实际是JVM在Linux下的bug 他想调用一个随机函数 但取不到 暂时的解决办法是 1)较好的解决 ...
- ArcGIS教程:公布地理处理服务
要公布地理处理服务.您须要两个元素:结果 窗体中的结果和到 ArcGIS Server 的管理员或公布者连接. 要公布服务,请右键单击结果并选择共享为 > 地理处理服务.例如以下图所看到的.此操 ...
- git-for-windows 安装无图标的问题
git-for-windows.ico 安装无图标的问题 一. 问题表现: 桌面图标与右建菜单图标,所是未知文件的图标, 二. 问题解决: 在shard/git/ copy 一个ico 文件(如git ...
- 香蕉派(or 皮?)上手初体验 -- 外观鉴赏,安装,配置&总结
一.前言及简单介绍 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbG9uZ2Vyem9uZQ==/font/5a6L5L2T/fontsize/400/f ...
- HDU 3466 01背包变形
给出物品数量N和总钱数M 对于N个物品.每一个物品有其花费p[i], 特殊值q[i],价值v[i] q[i] 表示当手中剩余的钱数大于q[i]时,才干够买这个物品 首先对N个物品进行 q-p的排序,表 ...