Basic Coder
Basic Coder

Reputation: 11422

Strange behavior reading demensions from XML

This is my dimens XML file:

<resources>    
    <dimen name="time_text_size">20dp</dimen>
    <dimen name="artist_text_size">20dp</dimen>
</resources>

This is my code:

int timeSize = res.getDimensionPixelSize(R.dimen.time_text_size);
System.out.println("timeSize: " + timeSize);
int artistSize = res.getDimensionPixelSize(R.dimen.artist_text_size);
System.out.println("artistSize: " + artistSize);

This is the console's result:

08-10 16:48:44.705: I/System.out(11866): timeSize: 40
08-10 16:48:44.705: I/System.out(11866): artistSize: 20

And this is my reaction: WTF!?

I get this error on my Tablet (Transformer Prime). On my Galaxy Nexus this works great and I got no problems with that.

Upvotes: 1

Views: 79

Answers (1)

Padma Kumar
Padma Kumar

Reputation: 20041

//actually you are running in xhdpi device

20 * 2 =40 px

if you have another dimen.xml in values-hdpi or values-xhdpi folder check the values are same that you might copy pasted there.

Upvotes: 1

Related Questions