[android-developers] How to set width and height of a View in DP through code not in XML ?

2011-01-26 Thread Mansoor
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

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] How to set width and height of a View in DP through code not in XML ?

2011-01-26 Thread Xu Jiyong
http://developer.android.com/guide/practices/screens_support.html

search 'Converting dp units to pixel units' on above page.


On Thu, Jan 27, 2011 at 1:47 PM, Mansoor mansoor@wipro.com wrote:

 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

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en