Setting height of ListView dynamically in run-time

by patrick » Wed, 21 May 2008 14:11:19 GMT

Sponsored Links

I want to set the height of a ListView during run-time of my
application. It seems that setPreferredHeight(int) doesn't do this job
and I can't find any similar function.

Did somebody already do something similar?


Setting height of ListView dynamically in run-time

by Mark Murphy » Wed, 21 May 2008 14:32:01 GMT


I haven't tried this, but here are two ideas:

1. It's possible you need to call requestLayout() on the ListView (or 
possibly the ListView's parent) after calling setPreferredHeight() to 
affect the change.

2. It's also possible that you really need to adjust the height field of 
the LayoutParams for your ListView (obtained through getLayoutParams()), 
then call requestLayout(). Check out the Layout section of the View 
class documentation to see what I mean: 

If either of those work, let us know!

Mark Murphy (a Commons Guy) 
The Busy Coder's Guide to Android Development -- coming in June 2008!


Sponsored Links

Setting height of ListView dynamically in run-time

by patrick » Wed, 21 May 2008 14:56:03 GMT

 Hi Mark,

this is the one that works! Here a small code snippet:

AbsoluteLayout al = (AbsoluteLayout)
ViewGroup.LayoutParams params = al.getLayoutParams();
params.height = 400;

where the height is specified in "px"


Other Threads

1. Drawing scaled bitmaps on a SurfaceView -- no antialiasing

Hi all,

I'm sorry if this topic has been brought before, but all my searches
on the web and this group did not help me.

I'm currently developing a little game with th Android SDK, and use hi-
res bitmaps that I resize accordingly
to match the device's resolution (letting the system do it for me is
not "crisp" enough).

I use a SurfaceView, on which I paint in one pass a canvas filling the
whole surface. The paint uses
setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)) to allow
Beforehand, I retrieve various bitmaps -- which are resized at
initialization with createScaledBitmap() and put in a cache --
and I apply the bitmaps with a paint on this canvas, before drawing
this canvas on the SurfaceView.

My problem is, whatever I try, whatever paint settings I use
(dithering, antialias, etc..), the resized bitmaps are not
antialiased and the drawing present jagged edges. I tried everything.
The only little success I had was using inSampleSize
to approach the desired scaled size and force a first pass of
antialiasing, before invoking createScaledBitmap on the retrieved
hi-res bitmap, but it is not beautiful enough. I just can't allow to
create multitudes of pre-sized bitmaps for every combination
of resolution. What did I miss ?

Thanks a lot in advance


2. Appending nodes to an existing XML file

Dear All,

I would like to append a node to an existing XML file.I  doesn't want to
rewrite the entire XML again.I just want to append the required node.

I hardly could find resources for this scenario.I badly need the
solution.Kindly help me.It would be great if you can give the entire source

Thanks in advance.

Thanks & Regards,


Please  Save paper,   Save trees.
Please don't print this email and documents unless it is really necessary.


3. Button Backgroundsetting error

4. GREF has increased to 201

5. Problem in Fetching Value from xml (xml parser problem)

6. What is the difference between Service and Invisible Frament.

7. Reliably erasing data from Android phones