Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android之實現上下左右翻頁效果

android之實現上下左右翻頁效果

編輯:關於Android編程

如果實現上下或者左右翻頁效果,我們借助下這個開源項目:https://github.com/openaphid/android-flip

Aphid FlipView是一個能夠實現Flipboard翻頁效果的UI組件。

下載完畢後導入到當前你的項目中,我們來下上下翻頁的效果圖:

\ \ \ \


<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PGJyPgo8L3A+CjxwPtaxvdPM+bP2tPrC66O6PC9wPgo8cD6yvL7WzsS8/qO6PC9wPgo8cD48L3A+CjxwcmUgY2xhc3M9"brush:java;">
主文件:

public class MainActivity extends Activity {
	private int[] image=new int[]{R.drawable.qd,R.drawable.qg,R.drawable.qw};
	private Context activity=this;
	protected FlipViewController flipViewController;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		flipViewController=new FlipViewController(activity);
		flipViewController.setAdapter(new baseAdapter());
		setContentView(flipViewController);
		
		
	}
	public class baseAdapter extends BaseAdapter{

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return image.length;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			if(convertView==null){
				convertView=new NumberTextVeiw(activity);
			}
			((ImageView)(convertView.findViewById(R.id.tv_number))).setBackgroundResource(image[position]);
			return convertView;
		}
		
		
		
	}
	private class NumberTextVeiw extends LinearLayout{
		ViewHolder viewHolder;
		public NumberTextVeiw(Context context) {
			super(context);
			inflate(context, R.layout.text_number_view, this);
			viewHolder=new ViewHolder();
			viewHolder.tv_number=(ImageView)findViewById(R.id.tv_number);
		}
	}
	private class ViewHolder {
		public ImageView tv_number;

	}

	
}

以上是實現上下翻頁效果的代碼,如果想實現左右翻頁只需更改一處代碼即可:

flipViewController=new FlipViewController(activity);
更改為:

flipViewController=new FlipViewController(this, FlipViewController.HORIZONTAL);

轉載請注明出處:http://blog.csdn.net/hai_qing_xu_kong/article/details/42215085 情緒控_






  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved