[android-developers] Re: Cannot define a float as a resource?
Thanks, Dianne. I am now just retrieving an int from 0 - 100 and divide it by 100 and set it as the weight. It works fine, but it's just extra code and I am lazy person, which is why I asked. :) On a related question: I am defining the width of my pop-up window as 500dp, this fits nicely into my HDPI screen on my Nexus One (480x800), but the same 500dp on an MDPI device (320x480) is wider than the screen and I need to set the width to 460dp. I would have thought using DIP as the unit of measure would deal with this. Thanks, Tom On Dec 23, 9:41 am, Dianne Hackborn wrote: > Oh also you can just do a percentage dimension ("50%") and retrieve it with > a base value of 1 or 100 as desired. > > On Wed, Dec 22, 2010 at 5:40 PM, Dianne Hackborn wrote: > > > > > > > You can use them as attributes, but unfortunately right now there is no way > > to get them as direct resources. > > > Well you can probably do it by being tricky -- use to define a raw > > resource, and Resources.getValue() to retrieve its value. > > > (One reason why this doesn't exist is if it made entries in R. for float > > values it would create code that can't compile since "float" is a keyboard. > > :p I solved that with ints by calling them integers, and booleans by > > calling them bools, but we never really needed floats so I never tried to > > come up with something to call them.) > > > On Wed, Dec 22, 2010 at 5:04 PM, Zsolt Vasvari wrote: > > >> Am I missing something or there is no mechanism to define a float > >> value as a resource? > > >> I am trying to have a locale dependent weight added to some of my > >> buttons. Right now, as a workaround, I am defining the weight as an > >> Integer and then divide and manualy set it. But why would there be > >> such a seemingly arbitrary decision made as not to allow floats but > >> allow ints? > > >> -- > >> 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 > > > -- > > Dianne Hackborn > > Android framework engineer > > hack...@android.com > > > 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 > hack...@android.com > > 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.- Hide quoted text - > > - Show quoted text - -- 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
[android-developers] Re: Cannot define a float as a resource?
Hi Dianne, I have never been able to successfully make MATCH_PARENT work. It seems to work for making the width (but not the height) of a floating Activity match the screen size, but I was never able to do the same for an AlertDialog. Here's an AlertDialog from my app using MATCH_PARENT for the AlertDialog's content view. No views inside have a specific size set: http://picasaweb.google.com/zvasvari/ScreenWidth#5554064956779202578 As you can see, it's way too narrow for the screen and, of course, it's even worse in landscape mode. Now here's the same dialog if I give it a minWidth of 300dp, nicely filling the screen. This is on a Nexus One (480x800): http://picasaweb.google.com/zvasvari/ScreenWidth#5554064961041980722 I've tried many-a-times in vain to make an AlertDialog expend to the screen size, but so far, I've been unsuccessful without giving it a minWidth. Zsolt On Dec 23, 3:44 pm, Dianne Hackborn wrote: > This is 500dp in the tall dimension? The two screens have different aspect > ratios, so the tall/wide dimensions are different. The scaling factor > between mdpi (160) and hdpi (240) is 1.5. 800 / 1.5 == 533. 480 * 1.5 == > 720. > > (And of course those aren't the only aspect ratios. QVGA is even shorter > (that is why it is a small screen), while some devices like droid are taller > at 480 x 852.) > > If you want to fill the screen, the easiest way to do this is to just make > your window's layout in that dimension be MATCH_PARENT. If you aren't using > MATCH_PARENT, your layout should be computing the size it needs based on its > content and using that, not trying to impose numbers to match the screen. > > (There is another level of complexity here when moving to significantly > larger screens. The phone screens are relatively simple, in that just > allowing the dialog fill the available width if it could at all use it ends > up working well. On an xlarge screen, though, that looks ridiculous. > Honeycomb should have some help for this problem...) > > > > > > On Wed, Dec 22, 2010 at 11:33 PM, Zsolt Vasvari wrote: > > Thanks, Dianne. I am now just retrieving an int from 0 - 100 and > > divide it by 100 and set it as the weight. It works fine, but it's > > just extra code and I am lazy person, which is why I asked. :) > > > On a related question: > > > I am defining the width of my pop-up window as 500dp, this fits nicely > > into my HDPI screen on my Nexus One (480x800), but the same 500dp on > > an MDPI device (320x480) is wider than the screen and I need to set > > the width to 460dp. I would have thought using DIP as the unit of > > measure would deal with this. > > > Thanks, > > Tom > > > On Dec 23, 9:41 am, Dianne Hackborn wrote: > > > Oh also you can just do a percentage dimension ("50%") and retrieve it > > with > > > a base value of 1 or 100 as desired. > > > > On Wed, Dec 22, 2010 at 5:40 PM, Dianne Hackborn > >wrote: > > > > > You can use them as attributes, but unfortunately right now there is no > > way > > > > to get them as direct resources. > > > > > Well you can probably do it by being tricky -- use to define a > > raw > > > > resource, and Resources.getValue() to retrieve its value. > > > > > (One reason why this doesn't exist is if it made entries in R. for > > float > > > > values it would create code that can't compile since "float" is a > > keyboard. > > > > :p I solved that with ints by calling them integers, and booleans by > > > > calling them bools, but we never really needed floats so I never tried > > to > > > > come up with something to call them.) > > > > > On Wed, Dec 22, 2010 at 5:04 PM, Zsolt Vasvari > > wrote: > > > > >> Am I missing something or there is no mechanism to define a float > > > >> value as a resource? > > > > >> I am trying to have a locale dependent weight added to some of my > > > >> buttons. Right now, as a workaround, I am defining the weight as an > > > >> Integer and then divide and manualy set it. But why would there be > > > >> such a seemingly arbitrary decision made as not to allow floats but > > > >> allow ints? > > > > >> -- > > > >> 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 > > > > > -- > > > > Dianne Hackborn > > > > Android framework engineer > > > > hack...@android.com > > > > > 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 > > > hack...@andro
[android-developers] Re: Cannot define a float as a resource?
Great, the setLayout call what I was looking for. Thank you. On Dec 24, 10:22 am, Dianne Hackborn wrote: > It definitely works; after all, this is how activities are full-screen. > > If nothing else, you can just set the theme of your dialog to @style/Theme > which will make it look and behave the same as a full-screen activity. ;) > > Be sure that you are setting this on the *window* not on the content view. > A WRAP_CHILD in a parent will cause its children to wrap as well; by > default a dialog as WRAP_CHILD for the width and height of the entire > window. You change this with Dialog.getWindow().setLayout(). > > > > > > On Thu, Dec 23, 2010 at 6:17 PM, Zsolt Vasvari wrote: > > Hi Dianne, > > > I have never been able to successfully make MATCH_PARENT work. It > > seems to work for making the width (but not the height) of a floating > > Activity match the screen size, but I was never able to do the same > > for an AlertDialog. > > > Here's an AlertDialog from my app using MATCH_PARENT for the > > AlertDialog's content view. No views inside have a specific size set: > >http://picasaweb.google.com/zvasvari/ScreenWidth#5554064956779202578 > > > As you can see, it's way too narrow for the screen and, of course, > > it's even worse in landscape mode. > > > Now here's the same dialog if I give it a minWidth of 300dp, nicely > > filling the screen. This is on a Nexus One (480x800): > >http://picasaweb.google.com/zvasvari/ScreenWidth#5554064961041980722 > > > I've tried many-a-times in vain to make an AlertDialog expend to the > > screen size, but so far, I've been unsuccessful without giving it a > > minWidth. > > > Zsolt > > > On Dec 23, 3:44 pm, Dianne Hackborn wrote: > > > This is 500dp in the tall dimension? The two screens have different > > aspect > > > ratios, so the tall/wide dimensions are different. The scaling factor > > > between mdpi (160) and hdpi (240) is 1.5. 800 / 1.5 == 533. 480 * 1.5 > > == > > > 720. > > > > (And of course those aren't the only aspect ratios. QVGA is even shorter > > > (that is why it is a small screen), while some devices like droid are > > taller > > > at 480 x 852.) > > > > If you want to fill the screen, the easiest way to do this is to just > > make > > > your window's layout in that dimension be MATCH_PARENT. If you aren't > > using > > > MATCH_PARENT, your layout should be computing the size it needs based on > > its > > > content and using that, not trying to impose numbers to match the screen. > > > > (There is another level of complexity here when moving to significantly > > > larger screens. The phone screens are relatively simple, in that just > > > allowing the dialog fill the available width if it could at all use it > > ends > > > up working well. On an xlarge screen, though, that looks ridiculous. > > > Honeycomb should have some help for this problem...) > > > > On Wed, Dec 22, 2010 at 11:33 PM, Zsolt Vasvari > > wrote: > > > > Thanks, Dianne. I am now just retrieving an int from 0 - 100 and > > > > divide it by 100 and set it as the weight. It works fine, but it's > > > > just extra code and I am lazy person, which is why I asked. :) > > > > > On a related question: > > > > > I am defining the width of my pop-up window as 500dp, this fits nicely > > > > into my HDPI screen on my Nexus One (480x800), but the same 500dp on > > > > an MDPI device (320x480) is wider than the screen and I need to set > > > > the width to 460dp. I would have thought using DIP as the unit of > > > > measure would deal with this. > > > > > Thanks, > > > > Tom > > > > > On Dec 23, 9:41 am, Dianne Hackborn wrote: > > > > > Oh also you can just do a percentage dimension ("50%") and retrieve > > it > > > > with > > > > > a base value of 1 or 100 as desired. > > > > > > On Wed, Dec 22, 2010 at 5:40 PM, Dianne Hackborn < > > hack...@android.com > > > > >wrote: > > > > > > > You can use them as attributes, but unfortunately right now there > > is no > > > > way > > > > > > to get them as direct resources. > > > > > > > Well you can probably do it by being tricky -- use to define > > a > > > > raw > > > > > > resource, and Resources.getValue() to retrieve its value. > > > > > > > (One reason why this doesn't exist is if it made entries in R. for > > > > float > > > > > > values it would create code that can't compile since "float" is a > > > > keyboard. > > > > > > :p I solved that with ints by calling them integers, and booleans > > by > > > > > > calling them bools, but we never really needed floats so I never > > tried > > > > to > > > > > > come up with something to call them.) > > > > > > > On Wed, Dec 22, 2010 at 5:04 PM, Zsolt Vasvari > > > > wrote: > > > > > > >> Am I missing something or there is no mechanism to define a float > > > > > >> value as a resource? > > > > > > >> I am trying to have a locale dependent weight added to some of my > > > > > >> buttons. Right now, as a workaround, I am defining the weight as > > an > > > > > >> Integer and then
[android-developers] Re: Cannot define a float as a resource?
You could always use floatToIntBits/intBitsToFloat. But keep in mind that the resources are actually char data anyway, and you might as well just use parseFloat on a String (though then you have to catch NumberFormatException). On Dec 23, 1:33 am, Zsolt Vasvari wrote: > Thanks, Dianne. I am now just retrieving an int from 0 - 100 and > divide it by 100 and set it as the weight. It works fine, but it's > just extra code and I am lazy person, which is why I asked. :) > > On a related question: > > I am defining the width of my pop-up window as 500dp, this fits nicely > into my HDPI screen on my Nexus One (480x800), but the same 500dp on > an MDPI device (320x480) is wider than the screen and I need to set > the width to 460dp. I would have thought using DIP as the unit of > measure would deal with this. > > Thanks, > Tom > > On Dec 23, 9:41 am, Dianne Hackborn wrote: > > > Oh also you can just do a percentage dimension ("50%") and retrieve it with > > a base value of 1 or 100 as desired. > > > On Wed, Dec 22, 2010 at 5:40 PM, Dianne Hackborn wrote: > > > > You can use them as attributes, but unfortunately right now there is no > > > way > > > to get them as direct resources. > > > > Well you can probably do it by being tricky -- use to define a raw > > > resource, and Resources.getValue() to retrieve its value. > > > > (One reason why this doesn't exist is if it made entries in R. for float > > > values it would create code that can't compile since "float" is a > > > keyboard. > > > :p I solved that with ints by calling them integers, and booleans by > > > calling them bools, but we never really needed floats so I never tried to > > > come up with something to call them.) > > > > On Wed, Dec 22, 2010 at 5:04 PM, Zsolt Vasvari wrote: > > > >> Am I missing something or there is no mechanism to define a float > > >> value as a resource? > > > >> I am trying to have a locale dependent weight added to some of my > > >> buttons. Right now, as a workaround, I am defining the weight as an > > >> Integer and then divide and manualy set it. But why would there be > > >> such a seemingly arbitrary decision made as not to allow floats but > > >> allow ints? > > > >> -- > > >> 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 > > > > -- > > > Dianne Hackborn > > > Android framework engineer > > > hack...@android.com > > > > 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 > > hack...@android.com > > > 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.- Hide quoted text - > > > - Show quoted text - -- 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] Re: Cannot define a float as a resource?
This is 500dp in the tall dimension? The two screens have different aspect ratios, so the tall/wide dimensions are different. The scaling factor between mdpi (160) and hdpi (240) is 1.5. 800 / 1.5 == 533. 480 * 1.5 == 720. (And of course those aren't the only aspect ratios. QVGA is even shorter (that is why it is a small screen), while some devices like droid are taller at 480 x 852.) If you want to fill the screen, the easiest way to do this is to just make your window's layout in that dimension be MATCH_PARENT. If you aren't using MATCH_PARENT, your layout should be computing the size it needs based on its content and using that, not trying to impose numbers to match the screen. (There is another level of complexity here when moving to significantly larger screens. The phone screens are relatively simple, in that just allowing the dialog fill the available width if it could at all use it ends up working well. On an xlarge screen, though, that looks ridiculous. Honeycomb should have some help for this problem...) On Wed, Dec 22, 2010 at 11:33 PM, Zsolt Vasvari wrote: > Thanks, Dianne. I am now just retrieving an int from 0 - 100 and > divide it by 100 and set it as the weight. It works fine, but it's > just extra code and I am lazy person, which is why I asked. :) > > On a related question: > > I am defining the width of my pop-up window as 500dp, this fits nicely > into my HDPI screen on my Nexus One (480x800), but the same 500dp on > an MDPI device (320x480) is wider than the screen and I need to set > the width to 460dp. I would have thought using DIP as the unit of > measure would deal with this. > > Thanks, > Tom > > On Dec 23, 9:41 am, Dianne Hackborn wrote: > > Oh also you can just do a percentage dimension ("50%") and retrieve it > with > > a base value of 1 or 100 as desired. > > > > On Wed, Dec 22, 2010 at 5:40 PM, Dianne Hackborn >wrote: > > > > > > > > > > > > > You can use them as attributes, but unfortunately right now there is no > way > > > to get them as direct resources. > > > > > Well you can probably do it by being tricky -- use to define a > raw > > > resource, and Resources.getValue() to retrieve its value. > > > > > (One reason why this doesn't exist is if it made entries in R. for > float > > > values it would create code that can't compile since "float" is a > keyboard. > > > :p I solved that with ints by calling them integers, and booleans by > > > calling them bools, but we never really needed floats so I never tried > to > > > come up with something to call them.) > > > > > On Wed, Dec 22, 2010 at 5:04 PM, Zsolt Vasvari > wrote: > > > > >> Am I missing something or there is no mechanism to define a float > > >> value as a resource? > > > > >> I am trying to have a locale dependent weight added to some of my > > >> buttons. Right now, as a workaround, I am defining the weight as an > > >> Integer and then divide and manualy set it. But why would there be > > >> such a seemingly arbitrary decision made as not to allow floats but > > >> allow ints? > > > > >> -- > > >> 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 > > > > > -- > > > Dianne Hackborn > > > Android framework engineer > > > hack...@android.com > > > > > 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 > > hack...@android.com > > > > 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.- Hide quoted text - > > > > - Show quoted text - > > -- > 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 > -- Dianne Hackborn Android framework engineer hack...@android.com 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 Grou
Re: [android-developers] Re: Cannot define a float as a resource?
It definitely works; after all, this is how activities are full-screen. If nothing else, you can just set the theme of your dialog to @style/Theme which will make it look and behave the same as a full-screen activity. ;) Be sure that you are setting this on the *window* not on the content view. A WRAP_CHILD in a parent will cause its children to wrap as well; by default a dialog as WRAP_CHILD for the width and height of the entire window. You change this with Dialog.getWindow().setLayout(). On Thu, Dec 23, 2010 at 6:17 PM, Zsolt Vasvari wrote: > Hi Dianne, > > I have never been able to successfully make MATCH_PARENT work. It > seems to work for making the width (but not the height) of a floating > Activity match the screen size, but I was never able to do the same > for an AlertDialog. > > Here's an AlertDialog from my app using MATCH_PARENT for the > AlertDialog's content view. No views inside have a specific size set: > http://picasaweb.google.com/zvasvari/ScreenWidth#5554064956779202578 > > As you can see, it's way too narrow for the screen and, of course, > it's even worse in landscape mode. > > Now here's the same dialog if I give it a minWidth of 300dp, nicely > filling the screen. This is on a Nexus One (480x800): > http://picasaweb.google.com/zvasvari/ScreenWidth#5554064961041980722 > > I've tried many-a-times in vain to make an AlertDialog expend to the > screen size, but so far, I've been unsuccessful without giving it a > minWidth. > > Zsolt > > > > > > > > > On Dec 23, 3:44 pm, Dianne Hackborn wrote: > > This is 500dp in the tall dimension? The two screens have different > aspect > > ratios, so the tall/wide dimensions are different. The scaling factor > > between mdpi (160) and hdpi (240) is 1.5. 800 / 1.5 == 533. 480 * 1.5 > == > > 720. > > > > (And of course those aren't the only aspect ratios. QVGA is even shorter > > (that is why it is a small screen), while some devices like droid are > taller > > at 480 x 852.) > > > > If you want to fill the screen, the easiest way to do this is to just > make > > your window's layout in that dimension be MATCH_PARENT. If you aren't > using > > MATCH_PARENT, your layout should be computing the size it needs based on > its > > content and using that, not trying to impose numbers to match the screen. > > > > (There is another level of complexity here when moving to significantly > > larger screens. The phone screens are relatively simple, in that just > > allowing the dialog fill the available width if it could at all use it > ends > > up working well. On an xlarge screen, though, that looks ridiculous. > > Honeycomb should have some help for this problem...) > > > > > > > > > > > > On Wed, Dec 22, 2010 at 11:33 PM, Zsolt Vasvari > wrote: > > > Thanks, Dianne. I am now just retrieving an int from 0 - 100 and > > > divide it by 100 and set it as the weight. It works fine, but it's > > > just extra code and I am lazy person, which is why I asked. :) > > > > > On a related question: > > > > > I am defining the width of my pop-up window as 500dp, this fits nicely > > > into my HDPI screen on my Nexus One (480x800), but the same 500dp on > > > an MDPI device (320x480) is wider than the screen and I need to set > > > the width to 460dp. I would have thought using DIP as the unit of > > > measure would deal with this. > > > > > Thanks, > > > Tom > > > > > On Dec 23, 9:41 am, Dianne Hackborn wrote: > > > > Oh also you can just do a percentage dimension ("50%") and retrieve > it > > > with > > > > a base value of 1 or 100 as desired. > > > > > > On Wed, Dec 22, 2010 at 5:40 PM, Dianne Hackborn < > hack...@android.com > > > >wrote: > > > > > > > You can use them as attributes, but unfortunately right now there > is no > > > way > > > > > to get them as direct resources. > > > > > > > Well you can probably do it by being tricky -- use to define > a > > > raw > > > > > resource, and Resources.getValue() to retrieve its value. > > > > > > > (One reason why this doesn't exist is if it made entries in R. for > > > float > > > > > values it would create code that can't compile since "float" is a > > > keyboard. > > > > > :p I solved that with ints by calling them integers, and booleans > by > > > > > calling them bools, but we never really needed floats so I never > tried > > > to > > > > > come up with something to call them.) > > > > > > > On Wed, Dec 22, 2010 at 5:04 PM, Zsolt Vasvari > > > > wrote: > > > > > > >> Am I missing something or there is no mechanism to define a float > > > > >> value as a resource? > > > > > > >> I am trying to have a locale dependent weight added to some of my > > > > >> buttons. Right now, as a workaround, I am defining the weight as > an > > > > >> Integer and then divide and manualy set it. But why would there > be > > > > >> such a seemingly arbitrary decision made as not to allow floats > but > > > > >> allow ints? > > > > > > >> -- > > > > >> You received this message because you are subscribed to the G