endryha
endryha

Reputation: 7256

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

Upvotes: 2

Views: 2725

Answers (2)

josephus
josephus

Reputation: 8304

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.

Upvotes: 5

Samuh
Samuh

Reputation: 36484

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

Upvotes: 0

Related Questions