如何避免与RelativeLayout重叠

3
我想要实现这样的布局:
enter image description here
我希望滚动从第一个ImageView的底部开始,到第二个ImageView的顶部结束。也就是说,我不希望ImageViews重叠在滚动上面。我不知道我是否解释清楚了。
首先,我尝试使用LinearLayout,但我无法将第二个ImageView与底部对齐。使用RelativeLayout,ImageViews会重叠在滚动上方,我可以设置滚动的margin-top来解决第一个ImageView的问题,但我不知道如何解决第二个ImageView的问题。
我还尝试在LinearLayout中使用RelativeLayout,像这样:

<LinearLayout ....>
<ImageView ...></ImageView>
<ScrollView...></ScrollView>
<RelativeLayout...>
<ImageView....></ImageView>
</RelativeLayout>
</LinearLayout>

但是第二个ImageView没有出现。我猜测滚动重叠在它上面。
如果有任何帮助,我会非常感激。谢谢你。


我该如何添加像以下的代码? - QuinDa
3个回答

6

使用

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/imageViewTop"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imageViewBottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:src="@drawable/ic_launcher" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/imageViewBottom"
        android:layout_below="@+id/imageViewTop"
        android:background="#006600" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

这是正确的答案。非常感谢你。 - RobertoAllende

0

你可以这样做

<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:background="@android:color/black"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" >

  <TextView
      android:id="@+id/topView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@android:color/white"
      android:text="top view" />

  <TextView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_above="@+id/bottomView"
      android:layout_below="@+id/topView"
      android:background="@android:color/holo_red_dark" />


<TextView
    android:id="@+id/bottomView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@android:color/white"
    android:text="bottom view" />

</RelativeLayout>

0
在你的xml文件中,将ListView放置在imageView1下方、imageView2上方。 确保使用RelativeLayout作为父布局。

将ImageView2放在底部(android:layout_alignParentBottom=true),将ImageView1放在顶部(android:layout_alignParentTop=true)。将列表视图放在imageview1下方并在imageview2上方。 - Kunal S. Kushwah
有另一种可怕的解决方案,使用滚动标题,但我不建议这样做。这是最简单的解决方案。 - wazaminator

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接