CalendarView dialogFragment使用较小的屏幕裁剪

时间:2017-09-29 12:02:50

标签: android

在较小的屏幕(480 x 854)上,日历仅显示月份,其余部分被截止。

片段的XML是一个FrameLayout,其宽度/高度与父级匹配,而CalendarView是wraps_content

按此按钮可显示日历

        dateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {;
            DialogFragment newFragment = new calendarDialogFragment();
            newFragment.show(getSupportFragmentManager(), "datePicker");
        }
    });

以下是dialogfragment的代码

    public  class calendarDialogFragment extends DialogFragment {
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             Bundle savedInstances) {
        View v = inflater.inflate(R.layout.calendar_view, container, false);
        return v;
    }
}

1 个答案:

答案 0 :(得分:0)

您可以创建一个BaseDialogFragment并将其大小覆盖。 然后让其他人扩展它:

    public class BaseDialogFragment extends DialogFragment {

        @Override
        public void onStart() {
            super.onStart();
            Dialog dialog = getDialog();
            if (dialog != null) {
                int width = (int) (getResources().getDisplayMetrics().widthPixels * 0.8f);
                int height = ViewGroup.LayoutParams.WRAP_CONTENT;
                if (null != dialog.getWindow()) {
                    dialog.getWindow().setLayout(width, height);
                }
            }
        }
}

根据您的需要调整宽度/高度

相关问题