开发者

Android: ListView fixed height of child view

开发者 https://www.devze.com 2023-01-09 06:41 出处:网络
Please advice how to set fixed heigh (in dip) for the child view of ListView component? I am using relative layout as root layout for the child view

Please advice how to set fixed heigh (in dip) for the child view of ListView component?

I am using relative layout as root layout for the child view

when I set backgoround image to relative layout it b开发者_JS百科ecomes very height (maybe because backgoround picture is large) and I want to set precisely the height in dp.


Stumbled on this problem while looking for an answer to a somewhat related question. Anyway, the problem is with inflating the view. In your getView (or newView if you're using CursorAdapter), when inflating a new layout, instead of doing

inflater.inflate(R.layout.your_layout, null)

do this instead:

inflater.inflate(R.layout.your_layout, parent, false)

Passing the parent view will make the child honor it's parents bounds, and false means you're instructing the inflater to NOT attach it to the parent. Setting a fixed height in dip will work after you do this.


For specifying the child height in dip via java code see following discussions:
1. setWidth in dip
2. how to specify padding in dip
3. Correct way to specify dimensions in Java code

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号