android - Why ImageView in XML and Java measurement different? -


i have following xml imageview:

    <imageview         android:id="@+id/iv"         android:layout_width="12dp"         android:layout_height="12dp"         android:src="@drawable/crossy"         android:scaletype="fitxy" /> 

when run following code:

iv = (imageview) findviewbyid(r.id.iv); log.i("iv wxh", ""+iv.getwidth() + " " + iv.getheight()); 

logcat shows following:

02-05 23:56:04.116: i/iv wxh(10211): 24 24

how ensure height , width stays same in code in xml?

the dp in xml file indicates measurement unit of "density independent pixels", while value logged java code telling measurement in actual pixels.

px = dp * (dpi / 160)

so in case, have 320 dpi screen, every 1 density independent pixels 2 physical pixels.

if want measurement in physical pixels, replace dp px in xml file. however, realize on device lower dpi, imageview take larger portion of screen.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -