<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromXDelta="-100%p"
android:toXDelta="0"/>
</set>
out_leftright.xml——从左到右出去屏幕:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromXDelta="0"
android:toXDelta="100%p"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromXDelta="100%p"
android:toXDelta="0"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromXDelta="0"
android:toXDelta="-100%p"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ViewFlipper
android:id="@+id/vf"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/sample_1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/sample_2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/sample_3" />
</LinearLayout>
</ViewFlipper>
</LinearLayout>
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ViewFlipper;
/**
* Created by panchengjia on 2016/11/28.
*/
public class FlipperActivity extends AppCompatActivity implements View.OnTouchListener{
private ViewFlipper vf;
float startX;//声明手指按下时X的坐标
float endX;//声明手指松开后X的坐标
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewflipper_layout);
vf= (ViewFlipper) findViewById(R.id.vf);
vf.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
//判断捕捉到的动作为按下,则设置按下点的X坐标starX
if(event.getAction()==MotionEvent.ACTION_DOWN){
startX=event.getX();
//判断捕捉到的动作为抬起,则设置松开点X坐标endX
}else if(event.getAction()==MotionEvent.ACTION_UP){
endX=event.getX();
//由右到左滑动屏幕,X值会减小,图片由屏幕右侧进入屏幕
if(startX>endX){
//进出动画成对
vf.setInAnimation(this,R.anim.in_rightleft);
vf.setOutAnimation(this,R.anim.out_rightleft);
vf.showNext();//显示下个view
//由左到右滑动屏幕,X值会增大,图片由屏幕左侧进入屏幕
}else if(startX<endX){
vf.setInAnimation(this,R.anim.in_leftright);
vf.setOutAnimation(this,R.anim.out_leftright);
vf.showPrevious();//显示上个view
}
}
return true;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有