0

What is the best solution for auto height in Android apps?

I have an image which is a set size and is necessary for the app. When I set the height and width to fill_parent, it puts the image half way up the screen.

When I change the height to wrap_content it goes down to the size of the image which is no good for scaling on devices.

Is it possible to have a height:auto as if it were CSS, or alternatively set the margin_top to be negative value (screenSize / 50%)

Josh Boothe
  • 1,413
  • 4
  • 25
  • 40

1 Answers1

0

You can put your views into linearlayout and set whem "weight" parameter something like this

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:gravity="top"
    android:hint="@string/message" />

Layout knows weight summ and gives to views their portion of screen

UPDATE

Look this about images scale

Community
  • 1
  • 1
Kirill Shalnov
  • 2,216
  • 1
  • 19
  • 21
  • I have put the above inside a linear layout (inside a relative layout) and the image has disappeared now. The order goes Rel Layout > Lin Layout > Image. There is an error on the `layout_height` saying that it will be invisible due to being `0dp` – Josh Boothe Jan 17 '15 at 21:12
  • It will be good, if you append your page layout and picture with wanted result – Kirill Shalnov Jan 17 '15 at 21:14
  • Updated answer, android:adjustViewBounds="true" – Kirill Shalnov Jan 17 '15 at 21:42