Sunday, October 18, 2009

[android-developers] Re: Custom View - obtain android:layout_width value

fhucho wrote:
> I did it this way:
> String widthString = attrs.getAttributeValue("http://
> schemas.android.com/apk/res/android", "layout_width");
> // now widthString can ba for example "150px", I need to convert it to
> int
> int s = Integer.parseInt(widthString.substring(0, 3));

I will reiterate my earlier point that I suspect what you are trying to
do here is not the right solution to your overall problem.

That being said, use getDimension() on the TypedArray that I provided in
my prior post. Your solution assumes you will always use pixels; I
sincerely hope you will consider other units of measure in the future
(e.g., dip). Also, your solution ignores any styles that may have been
applied to your widget -- obtainStyledAttributes() addresses this.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android App Developer Books: http://commonsware.com/books.html

--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate