android Xml生成一条细线,以及获取屏幕宽度和高度

<View
 android:layout_width="match_parent" 
android:layout_height
="2dip" android:background="#FF909090"
android:layout_marginLeft
="40dip" android:layout_marginRight="40dip"
android:layout_marginTop="10dip" />

转载http://www.cnblogs.com/henryxu/archive/2013/04/10/3012081.html

//android获取屏幕的高度和宽度用到WindowManager这个类,两种方法: 
 //第一种
WindowManager wm = (WindowManager) getContext()
                    .getSystemService(Context.WINDOW_SERVICE);
 
     int width = wm.getDefaultDisplay().getWidth();
     int height = wm.getDefaultDisplay().getHeight();
 //第二种
WindowManager wm = this.getWindowManager();
 
     int width = wm.getDefaultDisplay().getWidth();
     int height = wm.getDefaultDisplay().getHeight();

 

posted @ 2016-07-10 14:42  九天鲲鹏  阅读(2797)  评论(0编辑  收藏  举报