android平台的左右上下都能滚动的效果
2013-08-09 11:50:31 来源:WEB开发网核心提示:// int w = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);// int h = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UN
// 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 LinearLayout.LayoutParams(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(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
Log.i("AAA","gbList.size() = "+gbList.size());
return gbList.size();
}
public Object getItem(int position) {
赞助商链接