android平台的左右上下都能滚动的效果
android平台的左右上下都能滚动的效果
发布时间:2015-06-05 来源:查字典编辑
摘要:代码如下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);

}

}

}

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新安卓软件开发学习
热门安卓软件开发学习
编程开发子分类