关闭

ListView特效1

1591人阅读 评论(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"};
	
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:324081次
    • 积分:4188
    • 等级:
    • 排名:第7352名
    • 原创:90篇
    • 转载:51篇
    • 译文:4篇
    • 评论:30条
    最新评论