91在线一级黄片|91视频在线观看18|成人夜间呦呦网站|91资源欧美日韩超碰|久久最新免费精品视频一区二区三区|国产探花视频在线观看|黄片真人免费三级片毛片|国产人无码视频在线|精品成人影视无码三区|久久视频爱久久免费精品

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Android開發(fā)中不得不了解知識(shí)點(diǎn)

對(duì)于這樣的布局,我們可以用GridView控件或RecyclerView控件來實(shí)現(xiàn),提倡用RecyclerView控件來實(shí)現(xiàn)了。一屏顯示16個(gè)應(yīng)用,這樣就需要和屏幕的知識(shí)點(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; 

這里對(duì)于底部,我們得花點(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.             // 這個(gè)設(shè)備有一個(gè)導(dǎo)航欄   
  9.             return true;   
  10.         }   
  11.         return false;   
  12.     }  

我們要獲取屏幕的總高度減去 頂部高度和底部導(dǎo)航的高度(設(shè)備存在底部導(dǎo)航),如果你的屏幕還有其他控件,也要一起減去,再平均四等分。這樣我們的RecyclerView的每個(gè)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)載請(qǐng)聯(lián)系原作者】


分享標(biāo)題:Android開發(fā)中不得不了解知識(shí)點(diǎn)
鏈接地址:http://m.jiaoqi3.com/article/djoidcd.html