Tuesday, September 4, 2012

Re: [android-developers] Custom view's attributes

I've been reading some forums and I've seen two way for use it, with "app" and with "custom", but I don't know the difference. If someone can explain me I'll appreciate.

"app" and "custom" are basically shorthand ways of referencing your namespace... You can name it to be whatever you want...  Somewhere in your XML file (usually at the top) you would find a line that starts with something like this:

In each of those cases you would reference them as follows:

  • app:attribute_name=""
  • custom:attribute_name=""
  • anything_you_want_here:attribute_name=""


But the important question for me is that when I add the res/values/attrs for my custom ImageView, Eclipse doesn't autocomplete the default attributes for an ImageView like the "android:src" or "android:scaleType"

I'm not convinced it is smart enough to know that... I don't think I've ever seen the autocomplete come up with anything for custom attributes I've created, but I haven't really cared all that much either...

Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware


On Mon, Sep 3, 2012 at 8:27 AM, Pau Rodríguez Coloma <parodco@gmail.com> wrote:

Hi, 

I'm sublcassing an ImageView and adding one custom attribute like this in a res/values/attrs file:

<resources>

     <declare-styleable name="CustomImageView">

        <attr name="pattern" format="integer" />

    </declare-styleable>

</resources>


In my layout file I can use it like this:


<com.company.test.CustomImageView

            android:id="@+id/CustomImage"

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            android:layout_centerHorizontal="true"

            android:layout_alignParentTop="true"

            app:pattern="@drawable/example_drawable"

            /> 


I've been reading some forums and I've seen two way for use it, with "app" and with "custom", but I don't know the difference. If someone can explain me I'll appreciate.


But the important question for me is that when I add the res/values/attrs for my custom ImageView, Eclipse doesn't autocomplete the default attributes for an ImageView like the "android:src" or "android:scaleType"


Does anyone know why are this happening?


Thanks in advance. 

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

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

No comments:

Post a Comment