android - ImageView width incorrectly scaled on Nexus 4? -


i'm using technique described here. following line works on all devices, except nexus 4:

int imagewidth = horizontalscrollview.getchildat(0).getmeasuredwidth(); 

the layout simple:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >      <horizontalscrollview         android:id="@+id/main_scroller"         android:layout_width="match_parent"         android:layout_height="match_parent" >          <imageview             android:id="@+id/main_image"             android:layout_width="wrap_content"             android:layout_height="match_parent"             android:adjustviewbounds="true"             android:scaletype="centercrop" />     </horizontalscrollview> </relativelayout> 

into horizontalscrollview programmatically create bitmap around 500x1000 pixels. hence, image stretched fill roughly 1200x2400 (see centercrop). thus, width of imageview should 2400. , is! on nexus 7, samsung s3 mini , other low-density devices. not on nexus 4! on nexus 4, indeed have height stretched not width (yeah, unbelievable): 1000x1000 pixels. i've tried both getwidth() , getmeasuredwidth(). , when try scroll it, can see 50% of image horizontally (but 100% vertically).

update 1:

looking @ mdrawmatrix of imageview, can see differs:

nexus 7: matrix{[2.2979167, 0.0, 0.0][0.0, 2.2979167, 0.0][0.0, 0.0, 1.0]}

nexus 4: matrix{[2.1458333, 0.0, -623.0][0.0, 2.1458333, 0.0][0.0, 0.0, 1.0]}

update 2:

this bug in imageview.onmeasure() in android 4.2.2, fixed in 4.3. the question is, how add fix in 4.2.2? overriding onmeasure() not 100% trivial since lot of private functions being called.

i've had same issue on samsung galaxy s4 4.2.2 , s3 4.1.1, whatever did, programmatically-set bitmap not scale fill width of it's parent viewgroup. tried combinations of scaletype no avail.

for me solution set set density on bitmap specific value before displaying it.

        bitmap mybitmap = ...           // s3 , s4 confused displaying bitmaps without specific density,         // , fail scale them properly. setting density value helps (is possible density helps, haven't tested this)         mybitmap.setdensity(displaymetrics.density_high);          myimageview.setimagebitmap(mybitmap); 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -