Android ViewFlipper简单应用
短信预约 -IT技能 免费直播动态提醒
Android ViewFlipper 简单应用,废话不多说,直接看代码
activity_guide.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:id="@+id/guide"
tools:context="com.example.weijian.homeletterapplication.GuideActivity">
<ViewFlipper
android:id="@+id/Main_ViewFlipper"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ViewFlipper>
</LinearLayout>
GuideActivity.java
import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ViewFlipper;
public class GuideActivity extends AppCompatActivity implements GestureDetector.OnGestureListener {
private GestureDetector detector;
private ViewFlipper flipper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_guide);
//隐藏标题栏
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
detector = new GestureDetector(this);
flipper = (ViewFlipper) this.findViewById(R.id.Main_ViewFlipper);
flipper.addView(addImageView(R.mipmap.guide1));
flipper.addView(addImageView(R.mipmap.guide2));
flipper.addView(addImageView(R.mipmap.guide3));
}
private View addImageView(int id) {
ImageView iv = new ImageView(this);
//ImageView拉伸,充满整个ViewFlipper
iv.setScaleType(ImageView.ScaleType.FIT_XY);
iv.setImageResource(id);
return iv;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return this.detector.onTouchEvent(event);
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (e1.getX() - e2.getX() > 120) {
this.flipper.showNext();
}
if (e1.getX() - e2.getX() < -120) {
this.flipper.showPrevious();
}
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
}
您可能感兴趣的文章:Android使用ViewFlipper实现图片切换功能Android ViewFlipper的简单使用Android ViewFlipper翻转视图使用详解Android ViewFlipper用法实例分析Android ViewFlipper的详解及实例
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341