tabar被手机虚拟键挡住_bug_ _Popwindow被魅族手机自带虚拟键挡住完美解决
======== ?1
之前做了一個分享的功能,從底部彈出popwindow進行分享,但是由于部分手機自帶虛擬鍵,如魅族X4,所以彈出的popwindow被虛擬鍵擋住,
在網上找了好多資料,一些資料說把虛擬鍵隱藏,卻是可以實現,但是總覺得不符合要求。然后又看了一下qq的樣式,它彈出的popwindow在虛擬鍵之上,
然后就在網上找各種popwindow的demo,最后仔細查看一下代碼,才發現是我在設置popwindow的高度的時候將它的高度設置成了wrap_content,這里我覺得有必要給大家說一下fill_parent、wrap_content、match_parent的區別:
1)fill_parent
設置一個構件的布局為fill_parent將強制性地使構件擴展,以填充布局單元內盡可能多的空間。這跟Windows控件的dockstyle屬性大體一致。設置一個頂部布局或控件為fill_parent將強制性讓它布滿整個屏幕。
2) wrap_content
設置一個視圖的尺寸為wrap_content將強制性地使視圖擴展以顯示全部內容。以TextView和ImageView控件為例,設置為wrap_content將完整顯示其內部的文本和圖像。布局元素將根據內容更改大小。設置一個視圖的尺寸為wrap_content大體等同于設置Windows控件的Autosize屬性為True。
3)match_parent
Android2.2中match_parent和fill_parent是一個意思.兩個參數意思一樣,match_parent更貼切,于是從2.2開始兩個詞都可以用。那么如果考慮低版本的使用情況你就需要用fill_parent了
這里只需要將popwindow的高度設置成match_parent 就完美解決了問題,很高興有木有。
========== ?2 ?我在底部彈出一個popwindow 上面有幾個按鈕,在其他手機上沒有問題,但在魅族手機上 ,取消按鈕卻被遮擋了??,大家有遇到這個問題嗎?
前幾天剛好遇到過 現奉上解決辦法:
public static int getDpi(Activity activity) {
Display display = activity.getWindowManager().getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
int height = 0;
@SuppressWarnings("rawtypes")
Class c;
try {
c = Class.forName("android.view.Display");
@SuppressWarnings("unchecked")
Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
method.invoke(display, dm);
height = dm.heightPixels;
} catch (Exception e) {
e.printStackTrace();
}
return height;
}
public static int[] getScreenWH(Context poCotext) {
WindowManager wm = (WindowManager) poCotext
.getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
return new int[] { width, height };
}
public static int getVrtualBtnHeight(Context poCotext) {
int location[] = getScreenWH(poCotext);
int realHeiht = getDpi((Activity) poCotext);
int virvalHeight = realHeiht - location[1];
return virvalHeight;
}
關鍵是最后一個方法:獲取虛擬按鍵的高度,相信你的pop該彈多高 我就不多說了 都懂得
加個判斷,4.0以上才有
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= 14) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
總結
以上是生活随笔為你收集整理的tabar被手机虚拟键挡住_bug_ _Popwindow被魅族手机自带虚拟键挡住完美解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python读取包含层级关系的excel
- 下一篇: python excel模板 生成exc