rt,
MyViewGroup myvg = new MyViewGroup(this);
listView.addHeaderView(myvg, null, false);
结果listview列表里没显示headerView了!是不是addHeaderView里不能增加viewgroup这种。。listviewandroidaddHeaderViewviewgroup
MyViewGroup myvg = new MyViewGroup(this);
listView.addHeaderView(myvg, null, false);
结果listview列表里没显示headerView了!是不是addHeaderView里不能增加viewgroup这种。。listviewandroidaddHeaderViewviewgroup
private Context mContext;
private MyGallery gall;
public MyViewGroup(Context context) {
super(context);
// TODO Auto-generated constructor stub
mContext = context;
myAddView();
} @Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
int childCount = getChildCount();
int tempHeight = 0;
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
child.setVisibility(View.VISIBLE);
child.measure(r - l, b - t);
child.layout(0, tempHeight, child.getMeasuredWidth(), child
.getMeasuredHeight() + tempHeight);
tempHeight = tempHeight + child.getMeasuredHeight();
}
} public void myAddView(){
gall = new MyGallery(mContext);
gall.setAdapter(new MyImageAdapter(mContext));
gall.setOnItemClickListener(new OnItemClickListener() { @Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
});
addView(gall);
final TextView t = new TextView(mContext);
t.setBackgroundResource(R.drawable.top2);
t.setTextSize(18);
t.setTextColor(Color.rgb(77, 80, 67));
t.setText(" 本期头条");
addView(t);
}}