Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of incomplete display of Android custom LinearLayout layout

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the "Android custom LinearLayout layout display incomplete how to solve" the relevant knowledge, in the actual case of the operation process, many people will encounter such a dilemma, then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!

Find a problem

The original requirements, in a scaling list, custom LinearLayout inherits the LinearLayout dynamic add layout.

However, when it is implemented, a total of 30 pieces of data are traversed, but only one is displayed.

Breakpoint view code: the process of traversing addView () is a normal 30 cycles. Is that a matter of layout?

It doesn't feel wrong. Try adding a layer of LinearLayout vertically, wrap_content and match_parent to the outer layer of the custom layout. It's all tried, but it still doesn't work.

Android-Custom View does not display

Description:

A custom LinearLayout is defined and cannot be displayed.

The reason is that there must be

Public ManDaoH5View (Context context, AttributeSet attrs) {

This method is a custom LinearLayout initialization method, and LinearLayout's own properties must also be written in this method, otherwise the properties will not work, for example: setOrientation (VERTICAL)

Code:

Public class ManDaoH5View extends LinearLayout {public ManDaoH5View (Context context, AttributeSet attrs) {/ / this method must be available, otherwise the custom LinearLayout will not display super (context, attrs); setOrientation (VERTICAL); / / horizontal layout (its layout attributes must be written here, which will not work elsewhere) / / initChild (context, url) / / do not add this line. If the layout is referenced elsewhere, this method will be run. If the webview is not connected, an error will occur}}.

There are two solutions!

One: add to the layout file. Custom LinearLayout is also Liearlayout, how can you forget its direction?

Two: add to the construction method:

If you are directly new, the custom View is added in the constructor of a parameter; if you refer to the custom view in xml, it is referenced in the constructor of the two parameters; the constructor of the three parameters forgets what the call is (o (╯□╰) o)

SetOrientation (VERTICAL)

This is the end of the content of "how to solve the incomplete display of Android custom LinearLayout layout". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report