ListView特效1

public class TwoHeaderListView extends FrameLayout{

	private static final String TAG = "TwoHeaderListView";
	
	ImageView header1;
	ImageView header2;
	ListView listview;
	
	ImageView fixheader;

	
	public TwoHeaderListView(Context context) {
		super(context);
        init(context);
	}

	
	private void init(Context ctx){
		
		//固定头其实是另外的浮在上层的一个view和header2张的一样的一个view。
	    	fixheader = new ImageView(ctx);
	    	fixheader.setBackgroundColor(Color.RED);
	    	fixheader.setVisibility(View.GONE);

				
		header1 = new ImageView(ctx);		
		header2 = new ImageView(ctx);
		header1.setBackgroundColor(Color.GRAY);
		header2.setBackgroundColor(Color.RED);
		AbsListView.LayoutParams lp2 = new AbsListView.LayoutParams(LayoutParams.FILL_PARENT, 50);
		header2.setLayoutParams(lp2);
		header1.setLayoutParams(lp2);
		
		listview = new ListView(ctx);
		listview.setOnScrollListener(new OnScrollListener(){

			@Override
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				if (firstVisibleItem > 0){	
					fixheader.setVisibility(View.VISIBLE);//设置成可见
					fixheader.bringToFront();
				} else{
					fixheader.setVisibility(View.GONE);
				}
			}

			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
			}
			
		});
		

		this.addView(listview);	
		
		LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, 50);
	    this.addView(fixheader, lp);

	    
	    
		LinkedList<String> mListItems = new LinkedList<String>();
        mListItems.addAll(Arrays.asList(mStrings));

        adapter = new ArrayAdapter<String>(ctx,
                android.R.layout.simple_list_item_1, mListItems);
        

        listview.addHeaderView(header1);
        listview.addHeaderView(header2);
        listview.setAdapter(adapter);
		

	}
	
	ArrayAdapter<String> adapter = null;
	
    private String[] mStrings = {
            "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam",
            "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis",
            "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
            "Allgauer Emmentaler"};
	
}


阅读更多
个人分类: android
想对作者说点什么? 我来说一句

listView下拉刷新特效

2011年12月08日 129KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭