我的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" />
答案 0 :(得分:2)
使用像这样的RelativeLayout:
<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>