0

Problem: trying to give multi device support screen for a simple layout but in Nexus 6 its creating the problem,means not showing fit. It's side is cutting down where as per as docs for nexus-6 resolution is 1440*2560 and image should be in drawable-xxxhdpi .so i keep a image with resolution of 1440*2560.

<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:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon"
        android:id="@+id/imv" />
</RelativeLayout>

if i ll give match_parent so obvious it will stretch the image. Please help me to get out of it. Here is screen shots of screen -

http://s10.postimg.org/43od5j5h5/screen_shot_layout.png

  • use `android:scaleType="fitXY"` for fit image in `ImageView` – Chirag Savsani Dec 02 '15 at 13:13
  • @ChiragSavsani i know but it will stretch the image if not match the resolution – Nitish Srivastava Dec 02 '15 at 13:14
  • Then try to use 9patch drawable if possible. – Chirag Savsani Dec 02 '15 at 13:15
  • @ChiragSavsani image is not a kind of which can be make 9patch.is there any other way to use?like different folder or different image size? – Nitish Srivastava Dec 02 '15 at 13:19
  • have you tried (fiil_parent) instead of wrap_content? – Tasos Dec 02 '15 at 13:31
  • set both `android:layout_width` and `android:layout_height` to `match_parent` – pskink Dec 02 '15 at 13:31
  • ya but its again stretching the image – Nitish Srivastava Dec 02 '15 at 13:31
  • no, its not stretching – pskink Dec 02 '15 at 13:32
  • @pskink will stretch when you make it for full width – Nitish Srivastava Dec 02 '15 at 13:33
  • ok what do you mean by "stretch"? the aspect ratio will change? – pskink Dec 02 '15 at 13:36
  • set image width and height to 410 x 730 dp -- that should sort it out if you say the image is the right size for the nexus 6 -- and use (android:scaleType="center") --- http://android-developers.blogspot.com.cy/2014/10/getting-your-apps-ready-for-nexus-6-and.html – Tasos Dec 02 '15 at 13:37
  • @Tasos problem is not with the imageview because when you put it match_parent then it will go for the 410 in width but what size i have to give for the image.right now what you can see by the attached picture it is already at 1400 width and 2000 on height – Nitish Srivastava Dec 02 '15 at 13:43
  • @pskink yes its changing – Nitish Srivastava Dec 02 '15 at 13:44
  • ok then ill try a demo and run it in an emulator to see whats going on – Tasos Dec 02 '15 at 13:47
  • no, aspect ration is not changing when using the scale type other than FIT_XY or MATRIX, and you are using the default scale type so aspect ratio will NOT change – pskink Dec 02 '15 at 13:47
  • @Tasos thanks i will wait for your truthfull response – Nitish Srivastava Dec 02 '15 at 13:50
  • @pskink can you show as screen shot what exactly looking as or code – Nitish Srivastava Dec 02 '15 at 13:51
  • ImageView iv = new ImageView(this); iv.setImageResource(R.drawable.icon); setContentView(iv); – pskink Dec 02 '15 at 13:53
  • Ok i think i know whats happening Nexus 6 is 1440*2560. however the Navigation Bar and status bar also take up some extra pixels hence why i think the image gets scaled. try hiding both and see and see if pic fits in nicely --- http://s21.postimg.org/jxtae4p6f/Capture.jpg – Tasos Dec 02 '15 at 14:08
  • @Tasos you are going in right way,hope you can bring a solution. – Nitish Srivastava Dec 02 '15 at 14:39
  • yep, if im right i deserve a point cause screen size does not equal to content size in android cause of those bars they add on to the screen, although you can easyly hide them since kitcat -- you can see here what i mean -- http://www.emirweb.com/ScreenDeviceStatistics.php#Header253 - but they dont have Nexus 6 to check, but have a look at all the other Nexus – Tasos Dec 02 '15 at 14:47
  • Did you try setting width to fill_parent, height to wrap_content and android:adjustViewBounds="true" ? – Benjamin Fell Dec 02 '15 at 14:55
  • what do you mean a solution? email google and ask them (without the bars what are the exact dimensions of the content view for the Nexus 6 cause i went here http://www.emirweb.com/ScreenDeviceStatistics.php but they havent added it in yet). or ask on SO – Tasos Dec 02 '15 at 15:00

3 Answers3

0

If you want to fit the image on the imageview, replace android:src with android:background in the ImageView in the xml code.

Varun Kumar
  • 1,241
  • 1
  • 9
  • 18
0

Try to use these lines of code in the layout

 <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/icon"
    android:scaleType="fitXY"
    android:id="@+id/imv" />
Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
  • but it will stretch the image if not match the resolution as i have already mentioned above,is there any other way to match the criteria? – Nitish Srivastava Dec 02 '15 at 13:16
0

Set the width of the Image to fill_parent (you can set margins if you want a bit smaller imageView or you could also just set a fixed width)

Use android:adjustViewBounds to keep aspect ratio

Set height to wrap_content (it will take whatever it takes to maintain aspect ratio)

<ImageView
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:adjustViewBounds="true"
       android:src="@drawable/icon"
       android:id="@+id/imv"
       android:scaleType="fitCenter" />
Benjamin Fell
  • 393
  • 2
  • 11