当前位置:  开发笔记 > Android > 正文

调整DialogFragment的宽度和高度

如何解决《调整DialogFragment的宽度和高度》经验,为你挑选了0个好方法。

DialogFragmntWidth和存在问题Height。这是我的班级代表DialogFragmetn

public class RecipeAddDialogFragment extends DialogFragment {

    private ArrayList recipeDialogItems;
    private RecipeAddDialogAdapter recipeDialogAdapter;
    private String recipeUniqueId;
    private CoordinatorLayout coordinatorLayout;
    private RecipeAddDialogFragment recipeDialogFragment;

    @Override
    public void onStart() {
        super.onStart();
        if (getDialog() == null) {
            return;
        }

        int dialogWidth = 600;
        int dialogHeight = 300;
        getDialog().getWindow().setLayout(dialogWidth, dialogHeight);
        getDialog().setTitle(getString(R.string.recipe_dialog_title));
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setStyle(DialogFragment.STYLE_NORMAL, R.style.AppTheme_DialogFragment);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.dialog_fragment, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        recipeDialogItems = new ArrayList<>();
        RecyclerView dialogRecyclerView = (RecyclerView) view.findViewById(
                R.id.dialog_recycler_view);

        recipeDialogAdapter = new RecipeAddDialogAdapter(getContext(), recipeDialogItems,
                R.layout.recipe_dialog_item);
        recipeDialogAdapter.setRuidClRdf(recipeUniqueId, coordinatorLayout, recipeDialogFragment);

        dialogRecyclerView.setHasFixedSize(true);
        dialogRecyclerView.setAdapter(recipeDialogAdapter);
        dialogRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        fillRecipeDialogArray();
    }

    private void fillRecipeDialogArray() {
        String name = getString(R.string.add_to_favourites);
        int icon = R.drawable.ic_heart_48dp;;

        RecipeDialogItem dialogItem = new RecipeDialogItem();
        dialogItem.setRowIcon(icon);
        dialogItem.setRowOption(name);
        recipeDialogItems.add(dialogItem);

        recipeDialogAdapter.notifyDataSetChanged();
    }

    public void setReferences(String recipeUniqueId, CoordinatorLayout coordinatorLayout,
                              RecipeAddDialogFragment recipeDialogFragment) {
        this.recipeUniqueId = recipeUniqueId;
        this.coordinatorLayout = coordinatorLayout;
        this.recipeDialogFragment = recipeDialogFragment;
    }
}

这是.xml我在其中提出的DialogFragment




    
    

    
    


问题是,当我将其尺寸设置为600 x 300时,它在1280x720设备中可以正常显示,但是例如,当我的朋友在1920x1080分辨率对话框上显示它时,包装的对话框将只显示标题。列表已包装且未完整显示。知道如何自动设置其大小以适合每个显示并显示包装到其内容的整个对话框吗?

编辑

我已经想出要DialogFragment像这样调整其内容的宽度:

getDialog().getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT);
    getDialog().setTitle(getString(R.string.recipe_dialog_title));

但是高度不能正常工作:/

推荐阅读
mobiledu2402851323
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有