0

I have an imageview with a default image already set from the xml, and I want to change it's image pragmatically so that the new image will scale to the previous image size, both of the images are rounded.

I have tried setting the scaleType attribute to different values before setting the new image but it didn't work.

This is the xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >


<ImageView
    android:id="@+id/up_right_circle_firstiv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:scaleType="fitXY"
    android:src="@drawable/circle_medium_up" />

This is the activity code:

public class MainActivity extends Activity {
ImageView middleCircle;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    middleCircle = (ImageView) findViewById(R.id.up_right_circle_firstiv);
    middleCircle.setImageResource(R.drawable.round_pic_one);
}

}

Inside the activity.

I have uploaded the screenshots:

https://i.stack.imgur.com/oCTWJ.jpg

https://i.stack.imgur.com/BenUp.jpg

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
meh
  • 22,090
  • 8
  • 48
  • 58
  • 1
    I have updated the question, also setting the layout_width/height to an absolute value didn't help as well. – meh Oct 18 '12 at 09:25
  • 1
    Yup. He's (Lazy Ninja) right. Show us your screenshot. And, are you using imageView only in your XML Layout. Show full code. – Praveenkumar Oct 18 '12 at 09:27
  • CHECK [THIS][1] ! This may be the answer to your question. Hope it helps. [1]: http://stackoverflow.com/questions/8232608/fit-image-into-imageview-keep-aspect-ratio-and-then-resize-imageview-to-image-d – xknozi Oct 18 '12 at 09:30
  • Share your code, from that we can Start Discussing – gowri Oct 18 '12 at 09:40
  • I have edited the post so it will show the full code and I have added screenshots. – meh Oct 18 '12 at 09:47
  • It seems fine. What is the actual image of second one (people were there, that image). And, upload your image to imgur.com and paste the link it here for better. – Praveenkumar Oct 18 '12 at 09:51
  • I have uploaded both of the images to imagegur, the picture is bigger than the circle. – meh Oct 18 '12 at 09:54

1 Answers1

0

The solution that I have found was setting the layout_width and layout_height to a default size.

First I took the size of the original image file, then I have converted it to dp.

http://labs.skinkers.com/content/android_dp_px_calculator/

I had different image sizes for each resolution.

And then my xml looked something like this :

<ImageView
android:id="@+id/up_right_circle_firstiv"
android:layout_width="33dp"
android:layout_height="33dp"
android:src="@drawable/circle_medium_up" />

I only changed the dp values for each layout.

I know it is not the best solution but it worked for me.

meh
  • 22,090
  • 8
  • 48
  • 58