Android 为什么ImageView与UI重叠?

Android 为什么ImageView与UI重叠?,android,xml,layout,imageview,Android,Xml,Layout,Imageview,我在主活动的顶部添加了一个ImageView。我想知道是否有我丢失的属性或导致重叠的属性?有没有办法在不改变相对布局的情况下解决这个问题?我已经在下面发布了XML 因此,最初的UI如下所示: 添加ImageView后,它与输入框完全重叠: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools

我在主活动的顶部添加了一个ImageView。我想知道是否有我丢失的属性或导致重叠的属性?有没有办法在不改变相对布局的情况下解决这个问题?我已经在下面发布了XML

因此,最初的UI如下所示:

添加ImageView后,它与输入框完全重叠:

 <ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:gravity="center_vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
     >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:orientation="vertical" >

    <EditText
        android:id="@+id/ductDepth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/calc"
        android:layout_centerHorizontal="true"

        android:layout_marginBottom="37dp"
        android:ems="10"
        android:hint="@string/enter_duct_depth_mm"
        android:inputType="numberDecimal"
        android:singleLine="true" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/offDepth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView3"
        android:layout_alignLeft="@+id/ductDepth"
        android:layout_marginBottom="14dp"
        android:ems="10"
        android:hint="@string/enter_offset_depth_mm"
        android:inputType="numberDecimal"
        android:singleLine="true" />

    <EditText
        android:id="@+id/offLength"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView2"
        android:layout_alignLeft="@+id/offDepth"
        android:layout_marginBottom="20dp"
        android:ems="10"
        android:hint="@string/enter_offset_length_mm"
        android:inputType="numberDecimal"
        android:singleLine="true" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_above="@+id/offDepth"
        android:layout_alignLeft="@+id/offDepth"
        android:text="Depth:"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_above="@+id/ductDepth"
        android:layout_alignLeft="@+id/ductDepth"
        android:text="Duct Depth:"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_above="@+id/offLength"
        android:layout_alignLeft="@+id/offLength"
        android:text="Length:"
        android:textSize="30sp" />



    <android.support.v4.view.ViewPager     
    android:id="@+id/pager"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/calc" >

    <!--
    This title strip will display the currently visible page title, as well as the page
    titles for adjacent pages.
    -->

    <android.support.v4.view.PagerTitleStrip
        android:id="@+id/pager_title_strip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#33b5e5"
        android:paddingBottom="4dp"
        android:paddingTop="4dp"
        android:textColor="#fff" />

</android.support.v4.view.ViewPager>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="700dp"
        android:layout_height="700dp"
        android:layout_above="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="5dp"
        android:src="@drawable/mark3" />

    <Button
        android:id="@+id/calc"
        android:layout_width="200dp"
        android:layout_height="70dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="26dp"
        android:background="@drawable/calcbttrans" />

</RelativeLayout>

</ScrollView>



您使用的是相对布局,可以将ui元素置于其他元素之上,对于您的情况,我建议使用线性布局,可以垂直或水平放置ui元素。

这就是相对布局的作用。因此,如果有办法解决此问题……或者我必须更改布局吗?有趣的是,您正确地使用上面的布局和其他视图的此类参数。因此,如果我将标记更改为线性布局,不会像这样重叠吗?如果将其包装在滚动视图中,这会影响我的布局吗?您应该能够在滚动视图中使用线性布局。但是,该按钮需要保持在相对布局中才能位于底部,除非您认为它不在屏幕的最底部。我不认为像“android:layout_marginBottom”这样的属性在线性布局中会像在相对布局中一样工作,你需要做一些改变和实验来得到你想要的。