AttributeSet value returns @2131296269 - what is it and how to use?

If I define some view in xml like:

        <com.android.view.AlphabetButton
            android:id="@+id/buttonA"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:texSize="@dimen/alphabet_button_text_size"/>

and then at init with AttributeSet:

public AlphabetButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs!=null){

        String textSizeAttribute = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "textSize");

this textSizeAttribute value is like:

05-01 16:00:21.154: I/AlphabetButton(8738): textSizeAttribute @2131296269

which I assume is something like a link via R to needed attribute. The question is how to evaluate it? I tried:

if (textSizeAttribute.substring(0, 1).equals("@"))
                Log.i(this, "textSize is "+context.getResources().getDimension(Integer.valueOf(textSizeAttribute.substring(1))));

but this returns wrong value. If I define it like android:texSize="20sp" instead of @dimen-link then textSizeAttribute returns 20.0sp which is correct.

UPDATE I made an research and found that 2131296269 (0x7f09000d) links to correct value in my R.java:

    public static final class dimen {
        public static final int alphabet_button_width=0x7f09000b;
        public static final int alphabet_button_height=0x7f09000c;
        public static final int alphabet_button_text_size=0x7f09000d;
...

and dimens.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <dimen name="alphabet_button_width">30dp</dimen>
    <dimen name="alphabet_button_height">30dp</dimen>
    <dimen name="alphabet_button_text_size">20sp</dimen>
    ...

but it returns 30 instead of defined 20 can't figure why... Here is the log output:

05-01 16:18:14.284: I/AlphabetButton(9418): textSizeAttribute @2131296269 
05-01 16:18:14.284: I/AlphabetButton(9418): R.id is 2131296269 
05-01 16:18:14.284: I/AlphabetButton(9418): textSize is 30.0

and corresponding code lines:

public AlphabetButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (attrs!=null){

        String textSizeAttribute = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "textSize");
        Log.i(this, "textSizeAttribute "+textSizeAttribute);
        Log.i(this, "R.id is "+textSizeAttribute.substring(1));
        Log.i(this, "textSize is "+context.getResources().getDimension(Integer.valueOf(textSizeAttribute.substring(1))));

Answers


I'm dealing with this issue as well, and most likely android is scaling the original value of 20 up to 30 according the the screens density, which in your case is most likely 240 DPI, which would yield a scaling factor of 1.5

http://www.androidtablets.net/forum/android-tablet-usage-tips-tricks/9444-lcd-density-explained.html http://developer.android.com/guide/practices/screens_support.html

You can confirm these values by printing the following display metrics (in Mono/C#, needs minor translation for raw Android/Java):

this.ApplicationContext.Resources.DisplayMetrics.Density; this.ApplicationContext.Resources.DisplayMetrics.DensityDpi; this.ApplicationContext.Resources.DisplayMetrics.Xdpi; this.ApplicationContext.Resources.DisplayMetrics.Ydpi; this.ApplicationContext.Resources.DisplayMetrics.WidthPixels; this.ApplicationContext.Resources.DisplayMetrics.HeightPixels;


Need Your Help

Add custom attribute to an HTML input element with C#

c# html asp.net web-applications

I'm using the following method to add a custom attribute to a check box:

FilePrg with collections on ZF2

php file-upload collections zend-framework2 post-redirect-get

I need to submit a form which contains some fields along with a collection of max 3 images using fileprg plugin for saving uploaded files in case there has been some validation errors.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.