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();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM