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.

1
  • 1
    What adapter style are you using to populate your listview? That makes a difference in how you need to set your child's height. Commented Jul 27, 2010 at 17:41

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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?
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

4 Comments

I want to set child height in xml
moreover I want to have width as fill_parent but fixed height in dip
in XML just suffix the dimensions with "dip". E.g. layout_width = "50dip"
of course I know that, but when I have background larger then for instance 15dip the height becomes larger. I want to set fixed height nevertheless f background height

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.