0

I would like to get a ImageView width but all my results don't get me correct values.

I tryed: myImageView.getWidth(); but it return 0.

I also tryed: myImageView.getMeasuredWidth(); but it return 0 too.

And I tryed: myImageView.getLayoutParams().width; but it return -1.

My ImageView :

 <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/myImageViewId"
        android:src="@drawable/img"/>

And my activity:

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.myLayout);

    ImageView myImageView;
    myImageView = (ImageView)findViewById(R.id.myImageViewId);

    int width = myImageView.getLayoutParams().width;
    Log.d("Perso","width = "+width);
}

Do you know why I don't get a correct return ? Thank's advance.

LeNomade
  • 13
  • 7
  • Similar answer: http://stackoverflow.com/questions/12463155/get-the-displayed-size-of-an-image-inside-an-imageview – MaTePe Oct 17 '16 at 10:48
  • Thank's, I found the solution =) I use `ImageView.getDrawable.getIntrisicWidth`. It works great =) – LeNomade Oct 17 '16 at 11:58

0 Answers0