2

I want to develop an app for smartphones and tablets. Now my problem is that my layout isn't scalled in the right dimensens. On a 10' tablet it looks like this:

10' tablet

But this here are screenshoots from a 7' tablet and from a smartphone:

7' tablet

smartphone

I would like to set a min width and height for the ImageView and scale it up and down depending on the screen size so in each layout the ListView is visible. Which unit do I have to use for the ImageView width and height? I tried with dp, in and some more but that does not help...

Cilenco
  • 6,951
  • 17
  • 72
  • 152

1 Answers1

1

Use

<ImageView
    android:layout_width="@dimen/imageViewWidth"
    android:layout_height="@dimen/imageVewHeight"
    android:scaleType="fitXY"
/>

scaleType="fitXY" will scale your image and fit with ImageView width and height. This will solve your problem.

Edit

In your values directory, open strings.xml file, then add following lines

<dimen name="imageViewWidth">30dp</dimen>
<dimen name="imageViewHeight">30dp</dimen>

Now, open values-sw600dp directory (of not, create one) and open strings.xml file (if not, copy from other values directory).

<dimen name="imageViewWidth">100dp</dimen>
<dimen name="imageViewHeight">100dp</dimen>

Now, open values-sw720dp directory (of not, create one) and open strings.xml file (if not, copy from other values directory).

<dimen name="imageViewWidth">120dp</dimen>
<dimen name="imageViewHeight">120dp</dimen>

This will solve your problem of different sizes of ImageView for different layouts.

Still can't understand, read my answer at

Community
  • 1
  • 1
Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
  • okay thank you it's better now but I think not perfect. It's okay on a 7' tablet but on the smartphone it is still to big. I don't know how dp is calculated but I think there must be a factor to set the width and height. Can I edit this factor? – Cilenco May 21 '13 at 13:51