Explanation of Android custom control LinearLayout example

Many times, the controls commonly used in Android can't meet our needs, so we need to customize a control. Today, I made an example of a custom control to share. First, define a layout to realize the internal layout of the button:

Next, write a class that inherits LinearLayout, imports the layout just, and sets the required methods, so that you can control the display of the custom control content in the code.

Add this control to the layout that needs to use this custom control, just add it in XML.

The background image is used here in drawable / btn.xml

Finally, set this control in the activity, which is similar to other controls:

Finally, let's see the effect of our custom controls!

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>