Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non constant values #159

Closed
ankhers opened this issue Apr 17, 2012 · 5 comments
Closed

non constant values #159

ankhers opened this issue Apr 17, 2012 · 5 comments
Assignees
Milestone

Comments

@ankhers
Copy link

ankhers commented Apr 17, 2012

Forgive me if I skipped over the answer in a wiki entry, but how can I set a width or height value to something like 50pt?

I can't seem to find anything to deal with a height/width value that isn't :fill_parent, :wrap_content, though I have found that a regular integer is allowed. Nothing about other types of measurements (dp, sp, etc).

Thanks in advanced!

@rscottm
Copy link
Member

rscottm commented Apr 17, 2012

You can definitely put an integer value in the height/width fields (e.g.,
:layout => {:height= => 15}).

This sets the height field of:

http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html

That documentation does not specify unit of the integer at that moment. I'm
also not sure if there are any methods provided for easy conversion or if
you just have to do it yourself.

If you investigate this and get an answer, please post the result.

On Tue, Apr 17, 2012 at 1:05 PM, Justin Wood <
reply@reply.github.com

wrote:

Forgive me if I skipped over the answer in a wiki entry, but how can I set
a width or height value to something like 50pt?

I can't seem to find anything to deal with a height/width value that isn't
:fill_parent, :wrap_content, though I have found that a regular integer is
allowed. Nothing about other types of measurements (dp, sp, etc).

Thanks in advanced!


Reply to this email directly or view it on GitHub:
#159

@ankhers
Copy link
Author

ankhers commented Apr 18, 2012

Apparently you need to convert to pixels, here is what I came up with,

java_import 'android.util.TypedValue'

px = TypedValue.applyDimension TypedValue::COMPLEX_UNIT_PT, 50, getResources.getDisplayMetrics

This will get me the 50pt value in pixels that I asked for in my original question, you can then set your height/width normally

image_view :image_resource => $package::R.drawable.logo, :height => px

the various values in place of COMPLEX_UNIT_PT can be found here: http://developer.android.com/reference/android/util/TypedValue.html

I will see if I can make this a little easier, and send in a pull request.

@donv
Copy link
Member

donv commented Apr 20, 2012

@woodjk , please also consider updating the wiki with your findings.

@ankhers
Copy link
Author

ankhers commented Apr 20, 2012

@donv, done it can be found under tutorials and examples.

@ankhers ankhers closed this as completed Apr 20, 2012
@donv
Copy link
Member

donv commented Apr 20, 2012

Thanks!

@ghost ghost assigned rscottm Apr 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants