Reputation: 34517
Hello I am trying to set the image in the ImageView
but after setting the image it is appearing different in size on different android device.
Sony Z Experia 4.3
Samsung Y Dous 2.3 where it covered the entire image to the screen width
Here is layout
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="5dip"
android:scaleType="fitStart" />
How can I make such that it appear same as Sony Z Xperia. Any idea ?
Thanks in advance
Upvotes: 1
Views: 1771
Reputation: 292
Try this code and provide height and width in percentage of your screen
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
int widthScreen = metrics.widthPixels;
int heightScreen = metrics.heightPixels;
ImageView logo=findviewById(R.id.logo);
logo.getLayoutParams().height = (int) (heightScreen * 0.10);//it set the height of image 10% of your screen
logo.getLayoutParams().width = (int) (widthScreen * 0.10);
Upvotes: 0
Reputation: 59701
There are two ways you need to go about this.
<ImageView
android:id="@+id/logo"
android:layout_width="200dp"
android:layout_height="75dp"
android:padding="5dip"
android:scaleType="fitStart" />
Of course you could just use a single image (ignore #1) and use #2 to stretch it to the appropriate size, but then you might be scaling an image 10x bigger, and it will look very stretched.
Upvotes: 1
Reputation: 887
In android you have the option hdpi, mdpi, xdpi,etc..
folders for that , you have to create different images according your device resolution and put your images at there after confirming your device resolution and density category.
for the more reference why it'll happen you can see here
here i explain some chart may be helpful to you.
Low density Small screens QVGA 240x320 (120dpi):
layout-small-ldpi (240x320)
layout-small-land-ldpi (320x240)
Low density Normal screens WVGA400 240x400 (x432) (120dpi):
layout-ldpi (240 x 400 )
layout-land-ldpi (400 x 240 )
Medium density Normal screens HVGA 320x480 (160dpi):
layout-mdpi (320 x 480 )
layout-land-mdpi (480 x 320 )
Medium density Large screens HVGA 320x480 (160dpi):
layout-large-mdpi (320 x 480 )
layout-large-land-mdpi (480 x 320)
Galaxy Tab ( 240 dpi ):
layout-large (600 x 1024)
layout-large-land (1024 x 600)
High density Normal screens WVGA800 480x800 (x854) (240 dpi):
layout-hdpi (480 x 800)
layout-land-hdpi (800 x 480)
Xoom (medium density large but 1280x800 res) (160 dpi):
layout-xlarge (800 x 1280)
layout-xlarge-land (1280 x 800)
Upvotes: 3
Reputation: 5068
you need different images for different densities devices. Sony Z has higher density thats why its look smaller.xxdpi,xdpi,hdpi, mdpi and ldpi
folders are used for this thing. Try this tool to convert images for different devices. I know this tool is for icon only. its generate icons for different densities. but you can give it a try.
Upvotes: 0