1

我有以下情况:我需要在对话框框架中放置一个大图像(超出屏幕尺寸),但是我仍然需要对话框框架在顶部有大约 150dp 的边距(以便它后面的标题可见)。我可以通过让对话框超出屏幕来做到这一点,或者通过强制对话框的大小并将其 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>
4

0 回答 0