rt,
        MyViewGroup myvg = new MyViewGroup(this);
     listView.addHeaderView(myvg, null, false);
结果listview列表里没显示headerView了!是不是addHeaderView里不能增加viewgroup这种。。listviewandroidaddHeaderViewviewgroup

解决方案 »

  1.   

    public void addHeaderView(View v, Object data, boolean isSelectable)ViewGroup 是view的子类,肯定可以的
      

  2.   

    调用 setAdapter 后,header 会显示。 你可以把 MyViewGroup 代码粘出来吗?
      

  3.   

    public class MyViewGroup extends ViewGroup {
    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);
        }}