如果实现上下或者左右翻页效果,我们借助下这个开源项目:https://github.com/openaphid/android-flip
Aphid FlipView是一个能够实现Flipboard翻页效果的UI组件。
下载完毕后导入到当前你的项目中,我们来下上下翻页的效果图:
<喎�"http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PGJyPgo8L3A+CjxwPtaxvdPM+bP2tPrC66O6PC9wPgo8cD6yvL7WzsS8/qO6PC9wPgo8cD48L3A+CjxwcmUgY2xhc3M9"brush:java;">
主文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | <span style= "font-size:14px;" > 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; } }</span> |
以上是实现上下翻页效果的代码,如果想实现左右翻页只需更改一处代码即可:
1 | <span style= "font-size:14px;" >flipViewController= new FlipViewController(activity);</span> |
更改为:
1 | <span style= "font-size:14px;" >flipViewController= new FlipViewController( this , FlipViewController.HORIZONTAL);</span> |
转载请注明出处:http://blog.csdn.net/hai_qing_xu_kong/article/details/42215085 情绪控_
结伴旅游,一个免费的交友网站:www.jieberu.com
推推族,免费得门票,游景区:www.tuituizu.com