• android view可见性判断(判断是否在屏幕中显示)


    //java
    class UIUtils {
      public static int getScreenWidthInPx(Context context) {
      DisplayMetrics dm = context.getApplicationContext().getResources().getDisplayMetrics();
      return dm.widthPixels;
      }

      public static int getScreenHeightInPx(Context context) {
      DisplayMetrics dm = context.getApplicationContext().getResources().getDisplayMetrics();
      return dm.heightPixels;
      }
    }
    //kotlin
    fun isVisi(){
      var sH = UIUtils.getScreenHeightInPx(activity)
      var sW = UIUtils.getScreenWidthInPx(activity)
      val location = IntArray(2)
      view.getLocationInWindow(location);
      var a = location[0] < sW
      var b = location[1] < sH
      if(a && b){
        //在屏幕中是可见的
        // todo something
        return true
      }
      return false
    }

  • 相关阅读:
    *args, **kwargs
    python format函数
    python自省
    生成器与迭代器
    python面试题
    xpath和gzip
    python正则表达式
    cookie
    random
    杭电1710 (已知二叉树前中序 求后序)
  • 原文地址:https://www.cnblogs.com/zuiniub/p/16267713.html
Copyright © 2020-2023  润新知