2

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 becomes very height (maybe because backgoround picture is large) and I want to set precisely the height in dp.

endryha
  • 7,166
  • 8
  • 40
  • 64

2 Answers2

5

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.

josephus
  • 8,284
  • 1
  • 37
  • 57
  • Cool this works, but i dont understand what parents bounds has to do with child? its the childs bounds that need to be respected, not the parents? Also you say its not attached to parent yet it still is shown? – Tintinabulator Zea Sep 06 '15 at 01:35
0

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

Community
  • 1
  • 1
Samuh
  • 36,316
  • 26
  • 109
  • 116