###実現したいこと
画面上にあるTextViewをクリックしたときに表示させているカスタムダイアログを、
画面の角度(縦向き、横向き)が変わってもサイズを変えたくない。
###発生している問題・エラーメッセージ
縦画面にするとサイズが小さくなる。
###ボタンのレイアウト
java
1 2 <LinearLayout 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content" 5 android:layout_marginLeft="@dimen/dp_m" 6 android:layout_marginRight="@dimen/dp_m" 7 android:layout_marginTop="@dimen/dp_m" 8 android:layout_weight="1" 9 android:orientation="horizontal"> 10 <Button 11 android:id="@+id/bt_no0" 12 android:layout_width="0dp" 13 android:layout_height="match_parent" 14 android:layout_margin="@dimen/dp_s" 15 android:layout_weight="1" 16 android:background="@drawable/buttonbackground" 17 android:padding="@dimen/dp_l" 18 android:text="@string/no0" 19 android:textColor="@android:color/white" 20 android:textSize="@dimen/sp_m" />
dp_s は1dp
dp_m は4dp
dp_l は8dp
sp_s は16sp
sp_m は20sp
sp_l は24sp
です。
###カスタムダイアログ側の表示設定箇所
java
1// ダイアログの横幅、高さ、表示位置を設定 2 @Override 3 public void onActivityCreated(Bundle savedInstanceState) { 4 super.onActivityCreated(savedInstanceState); 5 WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); 6 DisplayMetrics metrics = getResources().getDisplayMetrics(); 7 lp.width = (int) (metrics.widthPixels * 0.4);//横幅を80% 8 lp.y = 162; //表示位置を指定した分、下へ移動 9 dialog.getWindow().setAttributes(lp); 10 } 11
###カスタムダイアログを表示する側の処理箇所
java
1 2final CustomizedDialog dialog = CustomizedDialog.newInstance(); 3ialog.show(getFragmentManager(), "dialog_fragment"); 4 dialog.setCancelable(false); 5 6
画面が縦向きの時・横向きの時で分岐して表示設定を変えればいいのでしょうか?
それともレイアウトの問題でしょうか?
解決策を教えてください。よろしくお願い致します。
あなたの回答
tips
プレビュー