How to set width and height of a View in DP through code not in XML ?

by Mansoor » Thu, 27 Jan 2011 13:47:47 GMT


Sponsored Links
 hi ,
i am creating a Image view  through code dynamically based on certain
condition as below:

ImageView t = new ImageView(mContext);
t.setLayoutParams(new LinearLayout.LayoutParams(390,
                                                                300));
the width and height is in PX i.e 390 PX and 300 PX

but i want to know how to set width and height in dp instead of px
programmatically . In xml we can do but i have no idea how to do it in
code
please help me .

Thanks
Mansoor V.M

-- 



Other Threads

1. SoundRecorder app breaks in MediaRecorder.prepare()

Hi,

I used to record audio using SoundRecorder application, but in latest
pull it seems to be broken. The application starts but when the record
is actually going to happen, it fails. The error message (from logcat)
is:

E/MediaRecorder(  869): prepare failed: -2147483648

I'd like to give more information about the error, but I don't see
more related messages in the log. I grep-ed the error message and
found that the "prepare" function is returning with an error. But I
couldn't find the actual implementation of the prepare function.

Any idea or suggestion?

Thanks,
-Misa

--~--~---------~--~----~------------~-------~--~----~

2. Built in http module in SDK

Hi,
Good morning.
I want to know that any http module/layer is available in the Android SDK
V1.
If there is any, in which file or in which folder I could find the source
code related to the HTTP module.

If any of you know about this please reply ASAP.

with regards,
Geetha

--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. orientation change crashes when ids are not unique

4. Support from Developers

5. News via WSJ ... 1 Million + G-Phones Sold So Far

6. the imageview object supports which formats images other than png and jpg

7. Test on real phone