【问题标题】:How to not overlapping with RelativeLayout如何不与 RelativeLayout 重叠
【发布时间】:2013-06-06 10:14:26
【问题描述】:

我正在尝试这样的布局:

好的,我希望滚动从第一个 imageview 的末尾开始,我希望滚动在第二个 imageview 的开头结束。我的意思是,我不希望图像视图与滚动重叠。不知道我解释的好不好。
首先,我尝试使用 LinearLayout,但无法在第二个 ImageView 的底部对齐。使用RelativeLayout,ImageViews重叠滚动,我可以将margin-top设置为滚动以解决第一个ImageView的问题,但我不知道如何解决第二个ImageView的问题。
我还尝试在 LinearLayout 中使用 RelativeLayout,如下所示:



滚动视图>





第二个 ImageView 没有出现。我猜滚动是重叠的。
我将不胜感激。谢谢你。

【问题讨论】:

  • 我怎样才能添加像下面1这样的代码?

标签: android layout


【解决方案1】:

使用

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

【讨论】:

  • 这是正确的答案。非常感谢。
【解决方案2】:

在您的 xml 中,将您的 ListView 放在 imageview1 下方和 imageView2 上方。 确保使用相对布局作为父级。

【讨论】:

  • 把ImageView2放在底部(android:layout_alignParentBottom=true),把ImageView1放在顶部(android:layout_alignParentTop=true)。将您的列表视图放在 imageview1 下方和 imageview2 上方
  • 还有另一个带有滚动头的可怕解决方案,但我不推荐它。这是最简单的解决方案
【解决方案3】:

你可以这样做

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多