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,
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
please help me .

Mansoor V.M


Other Threads

1. C2DM example ChromeToPhone, contents of "dataMessagingToken.txt"


I've been working/struggling with the C2DM examples to get them to
work in my setup. I have almost everything in place but I can't send
messages to the device because I haven't a  ClientLogin Auth token. In
the ChromeToPhone example this seems to be stored in

It's been a long day struggling with this, so does anyone know how I
get the token to store in this file? Will this token never change so
it's safe to store it in a textfile?



2. Launcher Pro Beta v0.6.7.2

Lha.. bukannya itu udah update 2 minggu yang lalu ya yang bisa
begitu.... hehehehe..... ada call dan sms counter nya juga kok.....



2010/7/14 Hadi Kusuma<>:

3. Help with Gestures please

4. AudioRecord API - STATE_UNITIALIZED - What do you do?

5. gunggu-EVoRoYo v0.9 , Froyo for EVO edisi id-android, testers wanted!!!

6. AppWidgetManager updateAppWidget throws NullPointerException

7. problems with the old and new Contact API