1

我想实现这个:

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>

有什么简单的方法可以做到这一点吗?或者我应该怎么做?

4

2 回答 2

2

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

您可以根据需要获得结果。

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

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

于 2013-07-10T13:29:46.187 回答
0

您不能根据屏幕尺寸在滚动视图内的底部设置图像视图,bcz 基于滚动视图内的内容,您的图像视图将设置为其位置。因此,将您的页眉和页脚图像固定在顶部和底部,并将您的内容放在滚动视图中。

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

于 2013-07-10T13:07:30.073 回答