【问题标题】:Overlapping ImageView in RelativeView在 RelativeView 中重叠 ImageView
【发布时间】:2011-12-06 22:24:37
【问题描述】:

正如我下面的代码所示,我有两个想要重叠的 ImageView,但较大的被系统地放在较小的下面,两者都是 android:layout_alignParentTop 设置为“true”,我认为这会导致重叠但Android 总是将它们一个一个地显示在另一个之下。

<RelativeLayout android:id="@+id/RelativeLayout1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:gravity="center_horizontal|center_vertical">
        <ImageView android:id="@+id/homeStars" android:src="@drawable/background" 
            android:layout_height="wrap_content" android:layout_width="fill_parent" android:scaleType="centerInside" 
            android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_alignParentTop="true"  
            />
        <ImageView android:id="@+id/homeLogo" android:src="@drawable/logo"
            android:layout_height="wrap_content" android:layout_width="220dip"
            android:layout_alignParentTop="true" android:layout_centerHorizontal="true"
            android:paddingTop="2dip" />
</RelativeLayout>

注意 1:我不希望将第一个设置为相对视图的背景。 注意 2:我应该补充一点,这个相对布局是放在 ScrollView 中的。

【问题讨论】:

  • 所以你现在的问题是它们重叠......?你想要他们做什么?
  • 如果一个在另一个后面......它们在什么方面不重叠?
  • 它在下面,而不是在后面:这正是我的问题。
  • 先添加你想要的视图,然后在前面添加你想要的另一个视图

标签: android android-relativelayout


【解决方案1】:
<RelativeLayout
    android:id="@+id/RelativeLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/homeStars"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerInside"
        android:src="@drawable/background" />

    <ImageView
        android:id="@+id/homeLogo"
        android:layout_width="220dip"
        android:layout_height="wrap_content"
        android:paddingTop="2dip"
        android:src="@drawable/logo" />

</RelativeLayout>

我删除了你们所有不同的 layout_* 标签,它工作正常。通过将自己定位在RelativeLayout 的左上角,所有孩子自然会相互重叠。您的额外标签不仅使我感到困惑,而且可能使解析器感到困惑。复制粘贴上面的代码,下次增量更改! :)

【讨论】:

  • RelativeLayout 的定位指令确实搞砸了。增量过程有效,但很耗时。谢谢。
【解决方案2】:

试试这个related post。 FrameLayout 将完成工作,即使您似乎非常热衷于 RelativeLayout。你可以妥协吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多