Add the dividing line as the last line of the ListView

Generally, we ListView layout as follows:

<ListView
        android:id="@+id/msgList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@color/list_divider"
        android:dividerHeight="@dimen/line"/>

List of items will appear in the dividing line, Bart, a listing if the three of the five elements, then the last page Item Below you will find no line, which is not so elegant, especially Item background is white, the page background is white, which is not so fine a.

Benbanfa has been used before, directly to the ListView divider set to empty android: divider = "@ null", then himself in each Item below draw a dividing line in the Item Adapter layout, the effect is achieved, but I felt too of agriculture, is there a better solution? Of course yes, as follows:

Step1: ListView's height to match_parent

<ListView
        android:id="@+id/msgList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@drawable/list_divider"
        android:dividerHeight="@dimen/line"/>

Step2: Set a property to Listview

mListView.setFooterDividersEnabled(true);

Remember, the above two conditions are indispensable, so the layout would not have crossed himself, and the last one at the end there will be the dividing line.

Published 59 original articles · won praise 88 · views 190 000 +

Guess you like

Origin blog.csdn.net/geofferysun/article/details/78071720