Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to introduce Custom layout in Android

Shulou Source: shulou.com Published: 2022-06-02 09:05:51 09月30日 Update

This article introduces you how to introduce custom layout in Android, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Mode of realization

There are two main processes to make a custom layout interface.

Construct the layout of a graphical interface

Reference to the implementation of graphical interface writing

Construct a graphical interface

We create a layout source file under the layout folder named title

We set a title, with the function name on the left, the user and the current organization on the right, as shown in the following figure

The code in xml is as follows:

Reference to the implementation of graphical interface writing

Create a class that inherits the RelativeLayout layout we just did, dynamically load the layout we just set, and then write specific functions to complete the setting of a custom control.

We can see that we can load the layout file through Layoutinflater.from in the layout above, load three TextView controls in the constructor, and then write two implementation methods to assign values to the text box.

At this point, even if the implementation of the custom layout file is complete, let's take a look at how to load the layout.

Implement loading custom layout

Let's build a new TestActivity.

To convert to the layout file, we refer to the layout we have just defined, named titlelayout

Then return to the code file we wrote the corresponding way, loaded the TitleLayout, and then write the implementation method.

Next, let's take a look at the effect of the implementation.

On how to introduce custom layout in Android to share here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Layout file interface typed mode two code content function name control method more help yes next three interest function dynamic Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Technology OPPO Reno Microsoft macOS