Failed to set the height of the ListView item

Set on the issue of the ListView item height, this blog-depth analysis of the source code, said very detailed.

 android listview item about setting a high degree of problem-solving methods

Bloggers conclusions can be summarized as follows:

Can not set the width and height in the outermost item layout file, otherwise invalid, android will automatically use the default internal layout parameters, namely MATCH_PARENT and WRAP_CONTENT. There are two solutions, a modified xml file, one is combined with the original LinearLayout layout based on the layout of the outermost width and height can be set to WRAP_CONTENT, it is to add another point code in the adapter's getView, set the layout parameters.

In this way the nested layout somewhat cumbersome, in fact, as long as the outermost layer of width and height of the layout file is not a specific value. There are many specific methods

1. If only one View layout (such as the TextView), then the height can be disposed on the TextView, the outer layer is set to wrap_content

2. The layout of a plurality of inner View, a sub-view may be selected to set the height, to hold up the entire height of the item. If this is not the case, the height may be provided a mask layer is fixed.

Guess you like

Origin blog.csdn.net/Smile_Qian/article/details/88692931