Android编程之界面跳动提示动画效果实现方法

2019-12-10 19:52:10王冬梅
  • private static boolean hasEverPulled = false;  private boolean pulled = false; 
  • private static int height;  private GestureDetector gestureDetector; 
  • private static int statusHeight = 0;  @Override 
  • protected void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState); 
  • setContentView(R.layout.activity_main);  DisplayMetrics metrics = getResources().getDisplayMetrics(); 
  • height = metrics.heightPixels;  statusHeight = getStatusHeight(); 
  • initView();  // 跳动提示可以上拉 
  • final Handler handler = new Handler();  handler.postDelayed(new Runnable() { 
  • @Override  public void run() { 
  • jump(thisDelta);  // handler.postDelayed(this, 3000); 
  • }  }, 3000); 
  • }  private void initView() { 
  • red = (RelativeLayout) findViewById(R.id.red);  blue = (RelativeLayout) findViewById(R.id.blue); 
  • switch2blue = (Button) findViewById(R.id.switch2blue);  switch2red = (Button) findViewById(R.id.switch2red); 
  • switch2blue.setOnClickListener(this);  switch2red.setOnClickListener(this); 
  • blue.setOnTouchListener(this);  blue.setLongClickable(true); 
  • gestureDetector = new GestureDetector(this, this);  } 
  • @Override  public void onClick(View arg0) { 
  • // TODO Auto-generated method stub  switch (arg0.getId()) { 
  • case R.id.switch2blue:  red2BlueUI(); 
  • break;  case R.id.switch2red: 
  • blue2RedUI();  break; 
  • }  } 
  • // 从红页面转到蓝页面  private void red2BlueUI() { 
  • blue.bringToFront();  blue.requestLayout(); 
  • blue.invalidate();  } 
  • // 从蓝页面转到红页面  private void blue2RedUI() { 
  • red.bringToFront();  red.requestLayout(); 
  • red.invalidate();  }