Android ViewFlipper的使用 实现页面滑动
来源:互联网 发布:现货知乎 编辑:程序博客网 时间:2024/06/10 23:02
点击打开链接 最近由于开发需要做一个滑动界面的效果的页面,自己以前也没什么接触过,刚开始的时候想用ViewPaper来实现的可是看看网上写的ViewPaper的示例觉得不适合自己的需要因为的第二个页面的需要用到第一个页面的数据,不想用Intent传数据那么麻烦通过找朋友终于找到了ViewFlipper这个东东。现在把ViewFlipper的使用简单做下比较。
1,main的布局文件,该布局文件要包含ViewFlipper。ViewFlipper下包含两个页面的布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <ViewFlipper android:id="@+id/vf_paper" android:layout_width="match_parent" android:layout_height="match_parent" > <include layout="@layout/paper1" /> <include layout="@layout/paper2" /> </ViewFlipper></RelativeLayout>
2,俩个被包含的页面
paper1.xml
<?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" > <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="3" android:src="@drawable/picture1" /> <Button android:id="@+id/bt_next" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="下一页" /></LinearLayout>
paper2.xml
<?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" > <Button android:id="@+id/bt_previous" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="上一页" /> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/picture2" /></LinearLayout>MainActivity.java文件
package com.lan.viewflippertest;import android.os.Bundle;import android.app.Activity;import android.view.View;import android.view.View.OnClickListener;import android.view.Window;import android.widget.Button;import android.widget.ViewFlipper;public class MainActivity extends Activity implements OnClickListener {private ViewFlipper fv_paper;private Button bt_next;private Button bt_previous;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main);fv_paper = (ViewFlipper) this.findViewById(R.id.vf_paper);bt_next = (Button) this.findViewById(R.id.bt_next);bt_next.setOnClickListener(this);bt_previous = (Button) this.findViewById(R.id.bt_previous);bt_previous.setOnClickListener(this);}public void onClick(View v) {// TODO Auto-generated method stubswitch (v.getId()) {case R.id.bt_next:fv_paper.setInAnimation(MainActivity.this, R.anim.right_in);fv_paper.setOutAnimation(MainActivity.this, R.anim.left_out);fv_paper.showNext();break;case R.id.bt_previous:fv_paper.setInAnimation(MainActivity.this, R.anim.left_in);fv_paper.setOutAnimation(MainActivity.this, R.anim.right_out);fv_paper.showPrevious();break;default:break;}}}
其中
fv_paper.setInAnimation(MainActivity.this, R.anim.right_in); fv_paper.setOutAnimation(MainActivity.this, R.anim.left_out); break; case R.id.bt_previous: fv_paper.setInAnimation(MainActivity.this, R.anim.left_in); fv_paper.setOutAnimation(MainActivity.this, R.anim.right_out); break;是动画效果,可以不用 ,四个动画效果xml
文件left_in.xml
<?xml version="1.0" encoding="utf-8"?><!-- 左进效果 --><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <translate android:duration="500" android:fromXDelta="0%p" android:interpolator="@android:anim/linear_interpolator" android:toXDelta="100%p" /></set>
left_out.xml
<?xml version="1.0" encoding="utf-8"?><!-- 左出效果 --><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <translate android:duration="500" android:fromXDelta="0%p" android:interpolator="@android:anim/linear_interpolator" android:toXDelta="-100%p" /></set>
right_in.xml
<?xml version="1.0" encoding="utf-8"?><!-- 右进效果 --><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <translate android:duration="500" android:fromXDelta="100%p" android:interpolator="@android:anim/linear_interpolator" android:toXDelta="0%p" /></set>
right_out.xml
<?xml version="1.0" encoding="utf-8"?><!-- 右出效果 --><set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <translate android:duration="500" android:fromXDelta="0%p" android:interpolator="@android:anim/linear_interpolator" android:toXDelta="100%p" /></set>
添加动画效果界面稍微好看了一些,但当点击上一页的时候页面会出现闪一下这个目前还找不到解决方法
ViewFlipperTest.rar
- Android ViewFlipper的使用 实现页面滑动
- 【Android基础知识】使用ViewFlipper实现页面左右滑动
- android viewflipper的使用 实现图片滑动效果
- Android 实现滑动翻页---使用ViewFlipper
- Android 滑动切换页面-ViewFlipper
- Android----ViewFlipper页面滑动基础
- Android使用ViewFlipper做页面切换,与手势滑动切换的使用。
- Android使用ViewFlipper做页面切换,与手势滑动切换的使用
- Android使用ViewFlipper做页面切换,与手势滑动切换的使用
- 我的Android进阶之旅------>Android使用ViewFlipper实现滑动翻页
- Android中实现滑动翻页—使用ViewFlipper
- Android中实现滑动翻页—使用ViewFlipper
- Android中实现滑动翻页—使用ViewFlipper
- Android中实现滑动翻页—使用ViewFlipper
- Android中实现滑动翻页—使用ViewFlipper
- Android中实现滑动翻页—使用ViewFlipper
- Android中实现滑动翻页—使用ViewFlipper
- Android使用ViewFlipper实现左右滑动效果面
- 改变你一生的30个关键习惯
- [leetcode] Subsets II
- android模拟器调整尺寸和内存大小
- Step Three: Escape!
- QString C程序员的注意事项
- Android ViewFlipper的使用 实现页面滑动
- 帮您快速入门 TI 的 Codec Engine
- linux菜鸟在ubuntu下编译了arm的c程序
- Android短信拦截
- PostgreSQL数据库、表空间、角色及用户
- 利用ffmpeg添加水印
- DB2 SQLCODE: -443, SQLSTATE: 38553
- SEO
- 领域特定语言