手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >android平台的左右上下都能滚动的效果
android平台的左右上下都能滚动的效果
摘要:代码如下publicclassGroupActivityextendsActivity{privateListgbList;//privat...

代码如下

public class GroupActivity extends Activity {

private List gbList;

// private MyListAdapter adapter;

private ItemClickEvent listener;

// private MyHandler handler;

private GridView[] gridvs ;

//

private LinearLayout ll_main;

private ScrollView scll ;

private LinearLayout scll_sub_ll;

private HorizontalScrollView hls;

private LinearLayout hls_sub_ll;

private GridView gv ;

private youtParams ll_pmm;

private youtParams ll_pmw;

private youtParams ll_pww;

private youtParams ll_head_wh;

private int headViewW = 0, headViewH = 0;

private TextView tv_type;

private View headView;

private LayoutInflater flater;

private Button bt_back, bt_right;

private TextView top_title;

private MyListAdapter[] myAdaps;

Handler hand = new Handler(){

public void handleMessage(Message msg) {

switch (msg.what) {

case 1:

Log.i("AAA","case1 "+msg.what);

if(null == gbList || gbList.size() < 0){

return;

}

init();

break;

case 2:

setContentView(ll_main);

break;

default:

break;

}

};

};

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

// setContentView(yout.main);

new Thread() {

@SuppressLint("NewApi")

public void run() {

gbList = new ArrayList();

for (int i = 0; i < 10; i++) {

TeamBean item = new TeamBean("abc" + i, "123456"

+ i);

Log.i("AAA","item = "+item);

gbList.add(item);

}

Message msg = Message.obtain();

msg.what = 1;

hand.sendMessage(msg);

}

}.start();

}

private void init(){

headView = getLayoutInflater().inflate(yout.dingbujiemian, null);

headView.setBackgroundResource(R.drawable.top_bg);

bt_back = (Button) headView.findViewById(R.id.zuobiananniu);

bt_back.setVisibility(View.VISIBLE);

bt_back.setBackgroundResource(R.color.transparent);

bt_back.setText(getResources().getString(R.string.fanhui));

bt_back.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

// TODO Auto-generated method stub

finish();

}

});

bt_right = (Button) headView.findViewById(R.id.youbiananniu);

bt_right.setVisibility(View.INVISIBLE);

top_title = (TextView) headView.findViewById(R.id.zhongjianzifu);

top_title.setVisibility(View.INVISIBLE);

ll_pmm = new youtParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

ll_pmw = new youtParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

ll_pww = new youtParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

// int w = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);

// int h = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);

// headView.measure(w, h);

// headViewW =headView.getMeasuredWidth();

// headViewH =headView.getMeasuredHeight();

// ll_head_wh = new youtParams(headViewW, headViewH);

// headView.setLayoutParams(ll_head_wh);

ll_main = new LinearLayout(this);

ll_main.setOrientation(LinearLayout.VERTICAL);

ll_main.setBackgroundColor(Color.WHITE);

ll_main.setLayoutParams(ll_pmm);

ll_main.addView(headView);

scll = new ScrollView(this);

scll.setLayoutParams(ll_pmm);

scll_sub_ll = new LinearLayout(this);

scll_sub_ll.setOrientation(LinearLayout.VERTICAL);

scll_sub_ll.setLayoutParams(ll_pmm);

int arrs[] = new int[15];

myAdaps = new MyListAdapter[arrs.length];

for (int i = 0; i < arrs.length; i++) {

hls = new HorizontalScrollView(this);

hls.setLayoutParams(ll_pmw);

hls.setBackgroundColor(Color.GRAY);

hls.setHorizontalScrollBarEnabled(false);

hls_sub_ll = new LinearLayout(this);

hls_sub_ll.setOrientation(LinearLayout.HORIZONTAL);

hls_sub_ll.setLayoutParams(ll_pmw);

gv = new GridView(this);

gv.setLayoutParams(ll_pmw);

LayoutParams params = new LayoutParams(gbList.size()

*(120+6) , LayoutParams.WRAP_CONTENT);

gv.setLayoutParams(params);

gv.setColumnWidth(120);

gv.setHorizontalSpacing(6);

/*gv.setStretchMode(gv.NO_STRETCH);*/

gv.setNumColumns(gbList.size());

myAdaps[i] = new MyListAdapter(GroupActivity.this);

listener = new ItemClickEvent();

if(i == arrs.length - 1){

}else{

gv.setAdapter(myAdaps[i]);

gv.setOnItemClickListener(listener);

}

hls_sub_ll.addView(gv);

hls.addView(hls_sub_ll);

tv_type = new TextView(this);

tv_type.setTextSize(22);

tv_type.setTextColor(Color.BLACK);

if(i == arrs.length - 1){

tv_type.setText("选中的好友 ");

}else{

tv_type.setText("朋友 "+i);

}

scll_sub_ll.addView(tv_type);

scll_sub_ll.addView(hls);

}

scll.addView(scll_sub_ll);

ll_main.addView(scll);

Message msg = Message.obtain();

msg.what = 2;

hand.sendMessage(msg);

}

private class MyListAdapter extends BaseAdapter {

private final String TAG = "MyListAdapter";

private LayoutInflater mInflater;

private final Context context;

public MyListAdapter(Context context) {

this.context = context;

mInflater = (LayoutInflater) context

.getSystemService(YOUT_INFLATER_SERVICE);

}

public int getCount() {

Log.i("AAA","gbList.size() = "+gbList.size());

return gbList.size();

}

public Object getItem(int position) {

return gbList.get(position);

}

public long getItemId(int position) {

return position;

}

@TargetApi(Build.VERSION_CODES.HONEYCOMB)

@SuppressLint("NewApi")

public View getView(int position, View convertView, ViewGroup parent) {

Log.i("AAA","position = "+position);

TeamBean item = gbList.get(position);

Log.i("AAA","getView() , item = "+item);

CellHolder cellHolder;

if (convertView == null) {

cellHolder = new CellHolder();

convertView = mInflater.inflate(yout.team_item, null);

cellHolder.ivIcon = (ImageView) convertView

.findViewById(R.id.ivIcon);

cellHolder.name = (TextView) convertView

.findViewById(R.id.name);

convertView.setTag(cellHolder);

} else {

cellHolder = (CellHolder) convertView.getTag();

}

cellHolder.ivIcon.setImageResource(R.drawable.icos5);

cellHolder.name.setText(item.getName());

cellHolder.name.setTextSize(12);

return convertView;

}

}

private class CellHolder {

ImageView ivIcon;

TextView name;

}

private class ItemClickEvent implements OnItemClickListener {

public void onItemClick(AdapterView parent, View view, int position,

long id) {

Log.i("item","parent = "+parent+", view = "+view+", position = "+position);

}

}

}

【android平台的左右上下都能滚动的效果】相关文章:

Android 用SQLite实现事务的方法

Android中实现动态切换组件背景的操作

基于Android SQLite的使用介绍

Android补间动画效果

Android支持的媒体格式

使用ViewPager实现高仿launcher左右拖动效果

android广播接收者实例

android平台AndEngine用粒子系统做的烟雾效果

android平台应用GPIO模拟IR控制车载DTV

android自动更新软件版本

精品推荐
分类导航