Chad Schultz
Chad Schultz

Reputation: 7860

How to make images resize instead of text disappearing when there isn't enough space?

When the screen is too small to contain all the layout elements at their natural size (say, for example, when a smaller screen goes to landscape mode) I notice that it looks like Android first conceals TextViews, and then shrinks images until they fit. That's my impression, maybe I'm not completely correct. My question is this: is it possible to make it resize images first? That way, the text would still be visible, even if the images need to be made quite small.

Here is one of many examples. The scaleType is irrelevant. From my observations, if Android doesn't have enough room on the screen and needs to decide whether to shrink an image or to crop/hide text... the text will be hurt first.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:src="@drawable/large_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerInside" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />



</LinearLayout>

Upvotes: 1

Views: 1190

Answers (2)

Blundell
Blundell

Reputation: 76526

Here try this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:src="@drawable/large_image"
        android:layout_width="wrap_content"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:scaleType="centerInside" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />



</LinearLayout>

That'll get your textview to wrap_content ie not shrink and the ImageView to take up the remaining space, therefore if it starts getting squashed it'll be the ImageView that is squished down.

If your worried about it getting too big, set a android:maxHeight="200dip" or something similar

Upvotes: 1

max4ever
max4ever

Reputation: 12142

http://developer.android.com/guide/practices/screens_support.html#qualifiers custom view for small screen on landscape mode should fix your problems

Upvotes: 0

Related Questions