1

I want to implement this:

I have an ImageView at the top of screen, always stays there. Above it I use an ScrollView, with some objects that depends on the Activity. And finally, I have another ImageView whose behaviour should be:

  • Stay in the bottom of the view with big screens, it is, when there is too much space after the objects inside ScrollView and before the end of the screen.

  • Be scrolled with small screens, it is, when all objects can't be seen, they will be scrollable, and I want to see that ImageView at the end.

Here is my code up to date

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".ContactoActivity"
    android:orientation="vertical" >

    <!-- LinearLayout with ImageView I have at the top of the view -->

    <ScrollView 
        android:id="@+id/scrollViewMain"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/linearLayoutLogoFactor_contacto"
        android:layout_marginTop="7dp">

        <RelativeLayout 
            android:id="@+id/relativeLayoutMain"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:focusable="true"
            android:focusableInTouchMode="true">

            <!-- Some other objects -->

            <!-- ImageView I want to stay at the bottom but being scrollable -->
            <LinearLayout
                android:id="@+id/linearLayoutImagenInferior_contacto"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/linearLayoutVerInfoContacto"
                android:gravity="center_horizontal" >

                <ImageView
                    android:id="@+id/imageViewImagenInferior_contacto"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:src="@drawable/la_electrica_de_las_empresas" />

            </LinearLayout>

        </RelativeLayout>

    </ScrollView>

</LinearLayout>

Is there any easy way for doing that? Or what should I do?

Lyd
  • 2,106
  • 3
  • 26
  • 33

2 Answers2

2

Try this code... In this Layout you have some objects above the Image and that have fix height, so, you need to use that height for below layout which contain the Imageview

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

<!-- LinearLayout with ImageView I have at the top of the view -->

<ScrollView 
    android:id="@+id/scrollViewMain"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    >

<LinearLayout
    android:id="@+id/relativeLayoutMain"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:focusable="true"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:focusableInTouchMode="true" >

    <LinearLayout
        android:id="@+id/ll_toast_new"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tv_toast"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:text="Hello, My self Sandip Chaniyara"
            android:textSize="20dp" />

        <TextView
            android:id="@+id/tv_toast2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:text="Hello, My self Sandip Chaniyara"
            android:textSize="20dp" />

        <EditText
            android:id="@+id/tv_toast1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            android:text="Hello, My self Sandip Chaniyara"
            android:textSize="20dp" >

            <requestFocus />
        </EditText>
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/linearLayoutImagenInferior_contacto"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         >

        <ImageView
            android:id="@+id/imageViewImagenInferior_contacto"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            android:src="@drawable/ic_launcher" />
    </RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>

You get the result as per your need.

in Large screen Image goto the bottom of the screen.and

in small screen you need to scroll the layout for show Image.

Mr.Sandy
  • 4,299
  • 3
  • 31
  • 54
  • But if I fix `marginTop` of `LinearLayout` of `ImageView`, it won't depends on screen, it will always be at same position in relation to the top of the screen. – Lyd Jul 10 '13 at 14:28
  • no no its not depend contain same position in relation to he top of the screen.but, it comes in small screen it put place for other subjects. otherwise it goto the bottom of the screen because it first check android:layout_alignParentBottom="true" property. – Mr.Sandy Jul 11 '13 at 05:43
  • you try my code and checked it out in all size its work as you said in your question. – Mr.Sandy Jul 11 '13 at 05:44
  • Ok, I've tried your code, now I will apply that to mine. But there is any other way not setting fix height for `LinearLayout` inside `ScrollView`? – Lyd Jul 11 '13 at 08:36
  • You tried out with any other way....and yes Imageview not need to fix height and width in my answer it works fine in wrap-content also.because image size is not fix everytime. – Mr.Sandy Jul 11 '13 at 08:43
  • Check my answer I edit it. and that not fix height for any layout.and it is compatible for you. – Mr.Sandy Jul 11 '13 at 08:53
  • Could you look at [that](http://stackoverflow.com/questions/17597389/android-image-is-seen-not-seen-when-orientation-is-changed) question, please? Maybe you could help me. – Lyd Jul 11 '13 at 16:20
0

You can't set image view at bottom inside a scroll view based on screen size, bcz based on the contents inside the scroll view your image view will be set to its position . So place your header & footer image fixed in top & bottom and put ur contents inside your scroll view.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ImageView
        android:id="@+id/imageViewHeader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_launcher" />

<ScrollView
    android:id="@+id/scrollViewMain"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/imageViewFooter"
    android:layout_below="@+id/imageViewHeader" >

    <RelativeLayout
        android:id="@+id/relativeLayoutMain"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:focusableInTouchMode="true" >

        <!-- Some other objects -->



    </RelativeLayout>
</ScrollView>

    <ImageView
        android:id="@+id/imageViewFooter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_launcher" />

  • How its work when 320*480 size image set in ImageView and device screen resolution same as Image size? – Mr.Sandy Jul 10 '13 at 13:31
  • Main Layout has to be a `LinearLayout` because if not, `ImageView` stays on top of last `Button` and it is not seen, so your solution isn't good for me. – Lyd Jul 10 '13 at 14:09