次のケースがあります: ダイアログ フレーム内に大きな画像 (画面サイズを超える) を配置する必要がありますが、ダイアログ フレームの上部に約 150 dp のマージンが必要です (その背後のタイトルが表示されるようにするため)。ダイアログを画面からはみ出すか、ダイアログのサイズを強制して y 位置を 150 などの値に設定することで、これを行うことができます。 、DialogFragment は画面の境界まで可能な限り拡大します (画面サイズがフルサイズの画像を保持するのに十分な大きさのデバイスで機能します)。したがって、垂直方向の開始位置 y は無視されます。この問題を解決する方法はありますか? これが私がこれまでに持っているコードです:
public static class MyDialogFragment extends DialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_TITLE, 0);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.findings_dialog, container, false);
Window window = getDialog().getWindow();
// window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
// WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
Display display = window.getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
WindowManager.LayoutParams p = window.getAttributes();
p.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;
p.x = 240;
p.y = 40;
p.height = 100;
// p.verticalMargin = 50.0f;
window.setAttributes(p);
// ScrollView scv = (ScrollView) v.findViewById(R.id.findingsPopup);
// ViewGroup.LayoutParams svcp = new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, height - 200);
// scv.setLayoutParams(svcp);
getDialog().setCanceledOnTouchOutside(true);
ImageView image = (ImageView) v.findViewById(R.id.findingsImage);
image.setImageResource(R.drawable.dummy_findings_picture); // TODO dummy image
Button closeButton = (Button) v.findViewById(R.id.closeButton);
closeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MyDialogFragment.this.dismiss();
}
});
// this.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
return v;
}
}
xml レイアウト ファイルは次のとおりです。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/findingsPopup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="100dp"
android:minHeight="50dp" >
<Button
android:id="@+id/closeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClose"
android:text="@string/close"
android:layout_marginLeft="200dp"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/closeButton" >
<ImageView
android:id="@+id/findingsImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:contentDescription="@string/logo"
android:src="@drawable/acute_myocarditis_cover" />
</ScrollView>
</RelativeLayout>