I have a ListView inside an AppWidget. Each row of the ListView has a custom layout, AppWidget specifies a minHeight, as required. The problem is that ListView exceeds the dimensions of the AppWidget, and some rows simply hang below the widget boundaries.
I have tried everything I could think of, fixing the height of ListView, using match_parent and/or wrap_content or rows and ListView, but I have not been able to fix this.
Has someone else faced this problem? How do I make the ListView fit inside the widget boundaries and scroll, instead of rows getting outside the boundary?
Well I have root-caused the issue, and I am to blame here, at least partly.
I am asked to use a custom background for the
ListView, and the 9-patch I received had a shadow drawn below the ‘content’ background. Android used the whole png for drawing the background, lending an appearance of ‘one row hanging off the content’ appearance to the widget.I verified this by using a solid color as background – it extends properly to cover entire
ListView.My learning:
1. The
minWidthandminHeightattributes for the widget are exactly what they say; Android WILL give more space to the widget if it can. 🙂2. You’ve specified “minimum” width, and your actual width is being determined by the width of a child
View. Given that such a case could be common, setting the top-level layoutwidthandheighttowrap_contentin the widget’s main view seems a reasonable thing to do.