(For the code you have, at mdpi the density scale is 1, so you just end up with a size of 11, which yes is pretty small.)
On Tue, Feb 15, 2011 at 9:07 AM, Dianne Hackborn <[email protected]>wrote: > That is the correct code. What do you mean by appearing very small? Of > course at mdpi it will be significantly smaller than hdpi. > > > On Tue, Feb 15, 2011 at 8:29 AM, Deepak Kumar > <[email protected]>wrote: > >> >> 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 < >> [email protected]> 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 [email protected] >>> To unsubscribe from this group, send email to >>> [email protected] >>> 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 [email protected] >>> To unsubscribe from this group, send email to >>> [email protected] >>> 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 [email protected] >> To unsubscribe from this group, send email to >> [email protected] >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> > > > > -- > Dianne Hackborn > Android framework engineer > [email protected] > > Note: please don't send private questions to me, as I don't have time to > provide private support, and so won't reply to such e-mails. All such > questions should be posted on public forums, where I and others can see and > answer them. > > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

