av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Android開發(fā)中不得不了解知識點(diǎn)

對于這樣的布局,我們可以用GridView控件或RecyclerView控件來實(shí)現(xiàn),提倡用RecyclerView控件來實(shí)現(xiàn)了。一屏顯示16個應(yīng)用,這樣就需要和屏幕的知識點(diǎn)聯(lián)系上了。

1、獲取頂部status bar 高度

 
 
 
 
  1. /** 
  2. * 獲取頂部status bar 高度 
  3. */ 
  4. private int getStatusBarHeight() { 
  5.     Resources resources = mActivity.getResources(); 
  6.     int resourceId = resources.getIdentifier("status_bar_height", "dimen","android"); 
  7.     int height = resources.getDimensionPixelSize(resourceId); 
  8.     Log.v("dbw", "Status height:" + height); 
  9.     return height; 

2、獲取底部 navigation bar 高度

 
 
 
 
  1. private int getNavigationBarHeight() { 
  2.     Resources resources = mActivity.getResources(); 
  3.     int resourceId = resources.getIdentifier("navigation_bar_height","dimen", "android"); 
  4.     int height = resources.getDimensionPixelSize(resourceId); 
  5.     Log.v("dbw", "Navi height:" + height); 
  6.     return height; 

這里對于底部,我們得花點(diǎn)心思,華為手機(jī)自帶下面有底部導(dǎo)航。我們要先通過判斷設(shè)備是否有返回鍵、菜單鍵(不是虛擬鍵,是手機(jī)屏幕外的按鍵)來確定是否有navigation bar

(已驗(yàn)證可行)。主要是KeyEvent.KEYCODE_BACK和hasPermanentMenuKey

 
 
 
 
  1. @SuppressLint("NewApi")    
  2.     public static boolean checkDeviceHasNavigationBar(Context activity) {   
  3.         boolean hasMenuKey = ViewConfiguration.get(activity)   
  4.                 .hasPermanentMenuKey();   
  5.         boolean hasBackKey = KeyCharacterMap   
  6.                 .deviceHasKey(KeyEvent.KEYCODE_BACK);   
  7.         if (!hasMenuKey && !hasBackKey) {   
  8.             // 這個設(shè)備有一個導(dǎo)航欄   
  9.             return true;   
  10.         }   
  11.         return false;   
  12.     }  

我們要獲取屏幕的總高度減去 頂部高度和底部導(dǎo)航的高度(設(shè)備存在底部導(dǎo)航),如果你的屏幕還有其他控件,也要一起減去,再平均四等分。這樣我們的RecyclerView的每個itemView才能均等。

3、屏幕高度

 
 
 
 
  1. DisplayMetrics displayMetrics = new DisplayMetrics(); 
  2. Activity activity = (Activity) mContext; 
  3. activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 
  4. LayoutParams layoutParams = holder.itemView.getLayoutParams(); 
  5. layoutParams.height = (displayMetrics.heightPixels - topHeight)/4; 
  6.  holder.itemView.setLayoutParams(layoutParams); 

其中topHeight為頂部、導(dǎo)航和其他控件的總高度。這樣就能實(shí)現(xiàn)我們的需求了。

【本文為專欄作者“洪生鵬”的原創(chuàng)稿件,轉(zhuǎn)載請聯(lián)系原作者】


分享文章:Android開發(fā)中不得不了解知識點(diǎn)
標(biāo)題來源:http://uogjgqi.cn/article/djoidcd.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流