2

我有一个Layout以我为中心,ScrollView我想在不移动它的位置ImageView的情况下放在它上面。Layout

我怎样才能做到这一点?

这是我的代码

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

    // LinearLayout with elements centered in ScrollView    
    <LinearLayout
        android:id="@+id/linearLayoutMain2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical" >

        ...Elements inside layout...

    </LinearLayout>
</ScrollView>

//ImageView I want to put just above LinearLayout without moving its position:
<ImageView 
    android:id="@+id/imageViewLogoFactor_main"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/logo_factorenergia" />
4

1 回答 1

4

像这样使用相对布局:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollViewMain"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
        <ImageView 
            android:id="@+id/imageViewLogoFactor_main"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon"
            android:layout_above="@+id/linearLayoutMain2"
            android:layout_centerHorizontal="true" 
            />        
        <LinearLayout
            android:id="@+id/linearLayoutMain2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:orientation="vertical"
            >
        </LinearLayout>
    </RelativeLayout>
</ScrollView>
于 2013-08-14T15:49:50.740 回答