Solve the problem of customized dialogfragment width and height in Android

For a detailed explanation of the basic usage of dialogfragment in Android applications, you can refer to it@ H_@ R_ 301_ 2409@_ 3@

1. Overview @ h_@ R_ 301_ 2409@_ 3@

Dialogfragment was introduced in Android 3.0. Is a special fragment used to display a modal dialog box on the content of the activity. Typical: display warning box, input box, confirmation box, etc@ H_@ R_ 301_ 2409@_ 3@

Before dialogfragment is generated, we create dialog boxes: alertdialog and dialog are generally used. Note: the official does not recommend directly using dialog to create dialog boxes@ H_@ R_ 301_ 2409@_ 3@

2. Benefits and usage @ h_@ R_ 301_ 2409@_ 3@

Using dialogfragment to manage dialog boxes can better manage its declaration cycle when rotating the screen and pressing the back key. It has basically the same declaration cycle as fragment. And dialogfragment also allows developers to reuse dialog as an embedded component, similar to fragment (different effects can be displayed on large and small screens). The above will show these benefits through examples ~ @ h_@ R_ 301_ 2409@_ 3@

Using dialogfragment requires at least the oncreateview or oncreatedialog methods. Oncreateview displays the dialog using the defined XML layout file. Oncreatedialog creates a dialog using alertdialog or dialog@ H_@ R_ 301_ 2409@_ 3@

Let's introduce the custom dialogfragment in Android to solve the problem of width and height through the example code @ H_@ R_ 301_ 2409@_ 3@

Customize the dialogfragment in Android to solve the problem of width and height, but we often want to fix the height of the dialogfragment, so we need to set the height of the dialogfragment and set the width and height of the window in the onresume() declaration cycle method of the fragment@ H_@ R_ 301_ 2409@_ 3@

Set the dialogframe to pop up from the bottom, and the pop-up animation is to slide up, and the disappearance animation is to slide down @ H_@ R_ 301_ 2409@_ 3@

The complete code is as follows: @ h_@ R_ 301_ 2409@_ 3@

Summary @ h_@ R_ 301_ 2409@_ 3@

The above is what Xiaobian introduced to you to solve the problem of width and height of customized dialogfragment in Android. I hope it will help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website@ H_@ R_ 301_ 2409@_ 3@

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>