zoukankan      html  css  js  c++  java
  • 图片自动切换, 滑动循环切换图片

    package com.lvtaozi.ui;

    import java.util.Timer;
    import java.util.TimerTask;

    import android.content.Context;
    import android.os.Handler;
    import android.os.Message;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.MotionEvent;
    import android.view.View;
    import android.widget.FrameLayout;

    import com.lvtaozi.activity.R;
    import com.lvtaozi.cellview.ShouYePMzhanshituCellView;
    import com.lvtaozi.cellviewmodel.ShouYePMzhanshituCellViewVM;

    public class ShouYeUI extends FrameLayout {
    private TitlebarUI shouyeTitlebarUI;
    private ShouYePMzhanshituCellView shouYePMzhanshituCellView;
    private ShouYePMzhanshituCellViewVM shouYePMzhanshituCellViewVM = new ShouYePMzhanshituCellViewVM();
    private float mPosX;
    private float mPosY;
    private float mCurrentPosX;
    private float mCurrentPosY;

    private int zhanshidibutuxiabuzhi = 0;

    public ShouYeUI(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
    }

    public void init() {
    LayoutInflater inflater = (LayoutInflater) getContext()
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.ui_shouye, this);

    shouyeTitlebarUI = (TitlebarUI) findViewById(R.id.shouyetitlebar);
    shouyeTitlebarUI.setLeftButtonImage(R.drawable.ic_launcher);
    shouyeTitlebarUI.setLeftButtonText("");
    shouyeTitlebarUI.setMidButtonText("锦融物业");
    shouyeTitlebarUI.setMidButtonTextSize(20);
    shouyeTitlebarUI.setRightTextViewImage(R.drawable.ic_launcher);
    shouyeTitlebarUI.setRightTextViewText("");

    shouYePMzhanshituCellView = (ShouYePMzhanshituCellView) findViewById(R.id.shouyepmzhanshitu);

    final Handler myHandler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
    // TODO Auto-generated method stub
    if (zhanshidibutuxiabuzhi == 2) {
    zhanshidibutuxiabuzhi = -1;
    }
    zhanshidibutuxiabuzhi = zhanshidibutuxiabuzhi + 1;
    initpmzhanshi(zhanshidibutuxiabuzhi);
    Log.d("Mytest", "timmer is running "+zhanshidibutuxiabuzhi);
    super.handleMessage(msg);
    }
    };
    new Timer().schedule(new TimerTask() {

    @Override
    public void run() {
    // TODO Auto-generated method stub
    Message message = new Message();
    message.what = 2;
    myHandler.sendMessage(message);
    }
    }, 0, 5000);

    shouYePMzhanshituCellView.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
    mPosX = event.getX();
    mPosY = event.getY();
    return true;
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
    mCurrentPosX = event.getX();
    mCurrentPosY = event.getY();
    //横向拖动大于50出发该事件
    if (mCurrentPosX - mPosX > 0
    && Math.abs(mCurrentPosX - mPosX) > 50) {
    Log.d("Mytest", "向右" + mCurrentPosX + " " + mPosX
    + " " + zhanshidibutuxiabuzhi);
    if (zhanshidibutuxiabuzhi == 0) {
    zhanshidibutuxiabuzhi = 3;
    }
    zhanshidibutuxiabuzhi = zhanshidibutuxiabuzhi - 1;
    initpmzhanshi(zhanshidibutuxiabuzhi);

    } else if (mCurrentPosX - mPosX < 0
    && Math.abs(mCurrentPosX - mPosX) > 50) {
    Log.d("Mytest", "向左" + mCurrentPosX + " " + mPosX
    + " " + zhanshidibutuxiabuzhi);
    if (zhanshidibutuxiabuzhi == 2) {
    zhanshidibutuxiabuzhi = -1;
    }
    zhanshidibutuxiabuzhi = zhanshidibutuxiabuzhi + 1;
    initpmzhanshi(zhanshidibutuxiabuzhi);
    }
    return true;
    }
    return false;
    }
    });
    }

    private void initpmzhanshi(int index) {
    if (index == 0) {
    Log.d("Mytest", "this is index " + index);
    shouYePMzhanshituCellViewVM.shiwaipmzhi = "左888";
    shouYePMzhanshituCellViewVM.shinei1pmzhi = "左44";
    shouYePMzhanshituCellViewVM.shinei2pmzhi = "左33";
    shouYePMzhanshituCellViewVM.xiabiaotu = String
    .valueOf(zhanshidibutuxiabuzhi);
    }
    if (index == 1) {
    Log.d("Mytest", "this is index " + index);
    shouYePMzhanshituCellViewVM.shiwaipmzhi = "中间888";
    shouYePMzhanshituCellViewVM.shinei1pmzhi = "中间44";
    shouYePMzhanshituCellViewVM.shinei2pmzhi = "中间33";
    shouYePMzhanshituCellViewVM.xiabiaotu = String
    .valueOf(zhanshidibutuxiabuzhi);
    }
    if (index == 2) {
    Log.d("Mytest", "this is index " + index);
    shouYePMzhanshituCellViewVM.shiwaipmzhi = "右888";
    shouYePMzhanshituCellViewVM.shinei1pmzhi = "右44";
    shouYePMzhanshituCellViewVM.shinei2pmzhi = "右33";
    shouYePMzhanshituCellViewVM.xiabiaotu = String
    .valueOf(zhanshidibutuxiabuzhi);
    }
    shouYePMzhanshituCellView.bind(shouYePMzhanshituCellViewVM);
    }

    }

    life is a jounery,yes
  • 相关阅读:
    Bootstrap(9) 巨幕页头缩略图和警告框组件
    Java使用点滴
    Bootstrap(8) 路径分页标签和徽章组件
    视频会议系统MCU服务器视频传输处理模式
    honeywell1900扫描枪的使用说明
    WebDev.WebServer20.exe应用程序错误
    UEFI引导过程及windows引导修复
    低分辨率的显示器模拟高分辨率显示模式
    IIS应用程序池权限与虚拟目录身份验证权限
    ADO.Net操作数据库的方式
  • 原文地址:https://www.cnblogs.com/CaptainLin/p/3679838.html
Copyright © 2011-2022 走看看