Android在底部设置了一个带有大屏幕的ImageView,并使用小屏幕滚动它

时间:2013-07-10 11:39:39

标签: android scroll imageview scrollview

我想实现这一点:

屏幕顶部有一个ImageView,一直呆在那里。在它上面我使用ScrollView,其中一些对象取决于Activity。最后,我有另一个ImageView,其行为应该是:

  • 使用大屏幕保持在视图的底部,当ScrollView内的对象和屏幕结束之前的空间太多时,它就是。

  • 滚动小屏幕,当所有对象都无法看到时,它们将可滚动,我希望最后看到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="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>

有没有简单的方法呢?或者我该怎么办?

2 个答案:

答案 0 :(得分:2)

试试这段代码...... 在此布局中,您在Image上方有一些对象并且具有固定高度, 因此,您需要将该高度用于包含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>

根据您的需要得到结果。

在大屏幕中图像转到屏幕底部。

在小屏幕中,您需要滚动显示图像的布局。

答案 1 :(得分:0)

您无法根据屏幕大小在滚动视图内的底部设置图像视图,基于滚动视图内容的bcz,您的图像视图将被设置为其位置。 所以放置你的标题&amp;页脚图像固定在顶部&amp;将你的内容放在滚动视图中。

<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" />