Reputation: 10341
I have imageView inside a relative layout. And when i create the activity i run thread to grap bitmap from the internet and set the imageView.
What i want is to resize the bitmap to scale based on relative view size while keeping the aspect ratio. The code for resizing the image is working but what i do is i get the relative view size by calling myRelativeView.getWidth()
& myRelativeView.getHeight()
and i feel that i should not do that because the docs say it could return 0. So what is the best way to retrieve the size of the relative view in this case ?
Upvotes: 1
Views: 9906
Reputation: 7263
FIX for your request :]
If you don't want to change size:
set your ImageView
scaleType
to "matrix"
If you want to change size but keep aspect ratio:
set your ImageView
scaleType
to "fitCenter" (or "fitStart", "fitEnd")
To change in code:
ImageView image;
image = (ImageView)findViewById(R.id.yourImageView1);
image.setScaleType(ImageView.ScaleType.FIT_CENTER);
To Change in XML: Example
<ImageView
android:layout_width="match_parent"
android:layout_width="match_parent"
android:scaleType="fitCenter"
android:src="ic_launcher"/>
Upvotes: 2
Reputation: 657
If the layout is in a proportion with the whole screen you can try:
Display display = getWindowManager().getDefaultDisplay();
width = display.getWidth()
//*proportion;or -dp; height = display.getHeight() //*proportion2;or -dp;
Upvotes: 0