views:

438

answers:

2

I have an ImageView at the top of my display that looks like the following:

╔══════════════════════════════════════════════╗
║ ImageView    ╔══════════════╗                ║
║              ║              ║                ║
║              ║ Actual image ║                ║
║              ║              ║                ║
║              ║              ║                ║
║              ║              ║                ║
║              ╚══════════════╝                ║
╚══════════════════════════════════════════════╝

Below this, I have a series of Buttons and TextViews..

I would like the ImageView's height to dynamically increase depending on the max height of the screen. I'm aligning the layout containing the buttons along the bottom of edge of the screen, and I would like the rest of the screen taken up by the above ImageView.

Also, since the ImageView contains a centered image, I would also like to set min height, and a scrollbar if the screen is too small to display the imageview and the buttons below.

Thanks!

Is this possible?

A: 

totally not the answer you're looking for but it is definitely possible through a mixture of relativelayout scrollview and dynamic coding through your class. not near a programming computer at the moment, but the vague answer is "possible? yes!" :)

Ben
+3  A: 

The first part should be pretty easy if you use android:layout_width. If you set the layout_width for only the ImageView (or its container), it will expand to take up as much of the parent layout as possible. For example, if you wanted a layout where an ImageView took up the entire rest of the screen, you'd do this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:src="@drawable/icon"
        android:scaleType="fitCenter" android:layout_weight="1" />
    <LinearLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <!-- Put whatever you want in here -->
    </LinearLayout>
</LinearLayout>

In this example I'm stretching the image to take up the entire screen, but you also present the problem of "what if the image is too large for the screen and I need scrolling?" In that case, all you need to do is add a ScrollView to the layout. If the image is too tall vertically, the screen will automatically scroll:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:fillViewport="true">
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="fill_parent">
        <ImageView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:src="@drawable/huge"
            android:scaleType="fitCenter" android:layout_weight="1" />
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <!-- Insert your content here -->
        </LinearLayout>
    </LinearLayout>
</ScrollView>

One important thing to note: if you don't have android:fillViewport set to true on the ScrollView, ImageViews that are too small will not fill up the entire screen.

Daniel Lew