首页 > 代码库 > android之实现上下左右翻页效果
android之实现上下左右翻页效果
如果实现上下或者左右翻页效果,我们借助下这个开源项目:https://github.com/openaphid/android-flip
Aphid FlipView是一个能够实现Flipboard翻页效果的UI组件。
下载完毕后导入到当前你的项目中,我们来下上下翻页的效果图:
直接贴出代码:
布局文件:
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" android:background="@android:color/white" > <ImageView android:id="@+id/tv_number" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="center" android:scaleType="fitXY" /> </LinearLayout></span>
主文件:
<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>
以上是实现上下翻页效果的代码,如果想实现左右翻页只需更改一处代码即可:
<span style="font-size:14px;">flipViewController=new FlipViewController(activity);</span>更改为:
<span style="font-size:14px;">flipViewController=new FlipViewController(this, FlipViewController.HORIZONTAL);</span>
转载请注明出处:http://blog.csdn.net/hai_qing_xu_kong/article/details/42215085 情绪控_
android之实现上下左右翻页效果
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。