I have a normal “read an article” type page with a single large photo at the top.
I’d like it to:
- not scale larger than the source imgae
- not be larger than the screen
- not be CRAZY long vertically
- side things I already have working
- border (via padding), center crop (would rather top crop, but seems not avail)
The main issue I’m having is – I can either have it fill_parent (ie full width) OR wrap_content (ie as large as the original image). And nothing I have done so far allows the image to be normal size (ie keep from enlarging).
Is there a “norm” for this kind of thing? I’m sure there’s some kind of sweet spot or combination of attributes for this that works – I just can’t find them.
My current attempt:
<ImageView
android:id="@+id/article_photo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/super_light_gray"
android:scaleType="centerCrop"
android:contentDescription="@string/articlePhoto"
android:cropToPadding="true"
android:layout_marginBottom="20dp"
android:padding="1dp"/>
You can write some code in the Activity to get the image size and display size.
If the image size exceeds display size set width to display, if not set to image size. If you want to be fancy you can find the ratio between the x and y and scale vertically also.