Note that there are some explanatory texts on larger screens.

plurals
  1. POFitting ImageView Horizontally
    primarykey
    data
    text
    <p>I am developing a sort of ebook application and I am trying to display an image in the following two ways. When the screen is in <code>portrait</code>, I have the image horizontally fitted and vertically centered. When the screen is in <code>landscape</code>, I want the image to fill the screen horizontally with the aspect ratio maintained. Since the images that I am using are longer than they are wide, I have a <code>ScrollView</code> to allow viewing of the entire image. </p> <p>How should I be scaling my <code>ImageView</code> to achieve this? I know that <code>FIT_CENTER</code> comes close to what I want to do, but since the image is narrower than it is tall, it does not fill the width. I tried <code>FIT_XY</code> with <code>setAdjustViewBounds</code> set to true but that still doesnt maintain my aspect ratio. Does anyone have any ideas?</p> <p>Here is my code so far:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:isScrollContainer="true" android:layout_height="wrap_content" android:scrollbars="vertical" android:layout_gravity="center_vertical|clip_horizontal" android:scrollbarAlwaysDrawVerticalTrack="true" android:id="@+id/Root"&gt; &lt;ScrollView android:id="@+id/ScrollView01" android:tag="scroller" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical|clip_horizontal"&gt; &lt;ImageView android:scaleType="fitCenter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/imgView" android:adjustViewBounds="true"&gt;&lt;/ImageView&gt; &lt;/ScrollView&gt; &lt;/LinearLayout&gt; </code></pre> <p><a href="http://i.stack.imgur.com/9J8IW.png" rel="nofollow">http://i.stack.imgur.com/9J8IW.png</a> This is in portrait. It is exactly as I want it. The image fits the width of the screen and aspect ratio is maintained.</p> <p><a href="http://i.stack.imgur.com/Kw68o.png" rel="nofollow">http://i.stack.imgur.com/Kw68o.png</a> This is in landscape. The image's aspect ratio is maintained and the scrollview works as needed, but I need the imageview to stretch the width of the screen</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload