Android -- FlipViewController的使用(jar文件)

1.  此控件的作用  

  类似于翻书一样,可以上下翻页的控件, 

2.  效果图

  技术分享   上下翻页的效果

3.  实现代码

  

package com.duguang.baseanimation.ui.flip;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.aphidmobile.flip.FlipViewController;
import com.duguang.baseanimation.R;

public class Issue51Activity extends Activity {

	
	/**
	 * 类似于翻书一样,可以上下翻页的控件,详细代码可以查看
	 * https://github.com/openaphid/android-flip/blob/master/FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipViewController.java
	 * 
	 */
	private FlipViewController flipView;

	@ Override
	protected void onCreate ( Bundle savedInstanceState ) {

		super.onCreate ( savedInstanceState );
		setTitle ( R.string.activity_title );

		flipView = new FlipViewController ( this );

		// 设置适配器
		flipView.setAdapter ( new MyBaseAdapter ( this ) );

		setContentView ( flipView );
	}

	@ Override
	protected void onResume ( ) {

		super.onResume ( );
		flipView.onResume ( );
	}

	@ Override
	protected void onPause ( ) {

		super.onPause ( );
		flipView.onPause ( );
	}

	// 自定义适配器
	private static class MyBaseAdapter extends BaseAdapter {

		// 准备加载布局的工具
		private LayoutInflater inflater;

		private MyBaseAdapter (
		               Context context ) {

			inflater = LayoutInflater.from ( context );
		}

		@ Override
		public int getCount ( ) {

			return 3;
		}

		@ Override
		public Object getItem ( int position ) {

			return position;
		}

		@ Override
		public long getItemId ( int position ) {

			return position;
		}

		@ Override
		public View getView ( int position ,
		                              View convertView ,
		                              ViewGroup parent ) {

			if (position == 0) {
				return inflater.inflate ( R.layout.activity_flip_page1 ,
				                              null );
			}
			else if (position == 1) {
				return inflater.inflate ( R.layout.activity_flip_page2 ,
				                              null );
			}
			else {
				return inflater.inflate ( R.layout.activity_flip_page3 ,
				                              null );
			}
		}
	}
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。