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));


On Oct 18, 2:30 pm, Mark Murphy <mmur...@commonsware.com> wrote:
> fhucho wrote:
> > I have a custom View, it is created from xml - how can I obtain the
> > android:layout:width value in the constructor View(Context x,
> > AttributeSet a) ?
>
> To get at a custom attribute, you would use code like this:
>
> TypedArray a=ctxt.obtainStyledAttributes(attrs,
>                                                 R.styleable.Meter,
>                                                 0, 0);
>
> max=a.getInt(R.styleable.Meter_max, 100);
> incrAmount=a.getInt(R.styleable.Meter_incr, 1);
> decrAmount=-1*a.getInt(R.styleable.Meter_decr, 1);
>
> a.recycle();
>
> (fromhttp://github.com/commonsguy/cw-advandroid/tree/master/Views/Meter/)
>
> For android:layout_width, presumably you would use
> android.R.styleable.ViewGroup_Layout_layout_width, though I have not
> tried that.
>
> However, in theory, that attribute should be handled for you, I would
> think. You would negotiate the size in onMeasure().
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android App Developer Training:http://commonsware.com/training.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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to