• Android 中状态栏、标题栏、View的大小及区分


    1、获得状态栏的高度(状态栏相对Window的位置):

    Rect frame = new Rect();

    getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);

    int statusBarHeight = frame.top;


    2、获得mView中显示内容的Top (不包括标题栏,指的是相对Window的位置,即:没有标题栏的时候,指的是状态栏的bottom在Window中的坐标;有标题栏的时候指的是标题栏的bottom在Window中的坐标)

    getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();  


    3、获得view中显示内容,与window无关,只和父控件有关

    如果布局文件中mView match_parent 那么top=0,bottom=mView.getHeight();


    4、获得屏幕的宽高:

    (1)

    getResources().getDisplayMetrics().heightPixels;

    getResources().getDisplayMetrics().widthPixels;

    (2)

    WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
    int width = wm.getDefaultDisplay().getWidth();//屏幕宽度

    int height = wm.getDefaultDisplay().getHeight();//屏幕高度

    (3)

    DisplayMetrics mDisplayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(mDisplayMetrics);
    int W = mDisplayMetrics.widthPixels;
    int H = mDisplayMetrics.heightPixels;

    (4)过时方法

    Display mDisplay = getWindowManager().getDefaultDisplay();
    int W = mDisplay.getWidth();
    int H = mDisplay.getHeight();

  • 相关阅读:
    引入包时“”与<>的区别
    Scanners
    一个SQLite数据库的LIKE查询和IN集合查询的代码实例
    @synchronized线程同步互斥锁
    makeKeyAndVisible
    NSString 数字判断
    UILabel UITextField UITextView
    (转载)JAVA SE6.0 中使用SplashScreen
    转帖(http://hi.baidu.com/johnehuang/blog/item/e1e96782a4b04e97f703a6dc.html)
    ce
  • 原文地址:https://www.cnblogs.com/ldq2016/p/6671924.html
Copyright © 2020-2023  润新知