@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
// 橫屏時取高度為寬度答朋,高度為為 warp_content
int screenWidth = displayMetrics.widthPixels;
int screenHeight = displayMetrics.heightPixels;
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
if(screenWidth>screenHeight){
params.width = (int)(screenHeight*1.1f);
params.height = (int)(screenHeight*0.9f);
}else{
params.width = (int)(screenWidth*0.8f);
params.height = (int)(screenHeight*0.6f);
}
getDialog().getWindow().setAttributes((WindowManager.LayoutParams) params);
super.onConfigurationChanged(newConfig);
}
@Override
public void onResume() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
// 橫屏時取高度為寬度,高度為為 warp_content
int screenWidth = displayMetrics.widthPixels;
int screenHeight = displayMetrics.heightPixels;
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
if(screenWidth>screenHeight){
params.width = (int)(screenHeight*1.1f);
params.height = (int)(screenHeight*0.9f);
}else{
params.width = (int)(screenWidth*0.8f);
params.height = (int)(screenHeight*0.6f);
}
getDialog().getWindow().setAttributes((WindowManager.LayoutParams) params);
super.onResume();
}
DialogFragment 設置橫豎屏各自寬高瓣铣,且適應屏幕旋轉
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門巨柒,熙熙樓的掌柜王于貴愁眉苦臉地迎上來樱拴,“玉大人,你說我怎么就攤上這事洋满【牵” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵牺勾,是天一觀的道長正罢。 經(jīng)常有香客問我,道長驻民,這世上最難降的妖魔是什么翻具? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮回还,結果婚禮上裆泳,老公的妹妹穿的比我還像新娘。我一直安慰自己柠硕,他們只是感情好工禾,可當我...
- 文/花漫 我一把揭開白布运提。 她就那樣靜靜地躺著,像睡著了一般闻葵。 火紅的嫁衣襯著肌膚如雪民泵。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼铅檩,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了莽鸿?” 一聲冷哼從身側響起,我...
- 正文 年R本政府宣布硼啤,位于F島的核電站,受9級特大地震影響斧账,放射性物質發(fā)生泄漏谴返。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一咧织、第九天 我趴在偏房一處隱蔽的房頂上張望嗓袱。 院中可真熱鬧,春花似錦习绢、人聲如沸渠抹。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽逼肯。三九已至耸黑,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間篮幢,已是汗流浹背大刊。 一陣腳步聲響...
推薦閱讀更多精彩內容
- 之前項目中有個關于橫豎屏的需求蛋叼,原本以為是很簡單的事情焊傅,隨便一些就能解決,但結果發(fā)現(xiàn)事實并不是這樣狈涮。網(wǎng)上也搜索了很...
- 針對上一版本發(fā)現(xiàn)還有一些問題 針對優(yōu)化處理 一 在APP中所需的設置 1.在配置中關閉屏幕方向 將控制權交給代碼(...
- 前言 現(xiàn)在大部分的智能移動設備通過自動旋轉歌馍,能夠自動切換去呈現(xiàn)最適合當前屏幕顯示的內容握巢,無疑大大提升了使用者的用戶...
- iOS8之后的屏幕旋轉和iOS6,7有很大不同松却,項目中自己之前遇到過這樣的需求暴浦,從A界面呈現(xiàn)B界面,如果A橫屏則呈...