Thanks for the code.It is proper for view alignment within layout in different devices.But for textSize of textview its not happening properly.
I am using following code:- TextView txtForIcon=new TextView(this); txtForIcon.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); txtForIcon.setTextSize(*Utils.dipsToPx(11,this))*; txtForIcon.setText(name); size 11 is for hdpi(480*854) but for mdpi(320*480).It is appearing very small. Thanks, On Tue, Feb 15, 2011 at 7:54 PM, Richard Leggett <richard.legg...@gmail.com>wrote: > You can look into writing a utility method e.g. : > > *public* *class* Util { > *private* *static* *float* *DIP_SCALE* = -1; > > *public* *static* *int* dipsToPx(*int* dips, Context context) { > *if*(*DIP_SCALE* == -1) *DIP_SCALE* = > context.getResources().getDisplayMetrics().density; > *return* (*int*)(dips * *DIP_SCALE* + 0.5f); > } > } > > and using that in your code... > > On 15 Feb 2011, at 14:13, Pepijn Van Eeckhoudt wrote: > > On 15/02/2011 15:03, Deepak Kumar wrote: > > One of the solution can be multiplying these values with > ratio (according to device).Is there any other way to do the same? > > In code, I define constants in 'dp' and then multiply with > DisplayMetrics#density<http://developer.android.com/reference/android/util/DisplayMetrics.html#density>at > runtime to get the correct pixel value. > > Pepijn > > -- > 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 > > > -- > 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 > -- 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