【问题标题】:Overlay for RelativeLayout inside ListView with match_parent使用 match_parent 覆盖 ListView 内的 RelativeLayout
【发布时间】:2014-05-24 10:01:50
【问题描述】:

我正在处理一个奇怪的问题。

我对@9​​87654321@ 行使用以下布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:jn="http://schemas.android.com/apk/res/com.appeaser.justnoteproject"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <BUNCH OF VIEWS />

    <RelativeLayout
        android:id="@+id/rlCon"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="@dimen/margin_note_bottom"
        android:layout_marginLeft="@dimen/margin_note_left"
        android:layout_marginRight="@dimen/margin_note_right"
        android:layout_marginTop="@dimen/margin_note_bottom" >

    <BUNCH OF VIEWS />

    <View
        android:id="@+id/vOverlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/blue_overlay"
        android:visibility="gone" />
    </RelativeLayout>

</RelativeLayout>

在我的列表适配器中,我根据特定条件切换 vOverlay's 可见性。但是,即使在切换可见性之后,vOverlay 也不会显示。

为了验证代码是否按预期工作,我将vOverlay 的高度和宽度更改为50dp。当我这样做时,vOverlay's 可见性按预期工作 - 除了我需要的大小是 match_parent

有人可以解释我做错了什么吗?我怎样才能获得预期的结果?

【问题讨论】:

  • 如果你给大小匹配父级。那么它将覆盖整个屏幕..只需将其更改为 wrap_content
  • @MeenalSharma 我刚才试过wrap_content。尽管如此,vOverlay 仍然不可见。
  • 用 FrameLayout 替换外部 RelativeLayout 并将您的叠加层移动到该 FrameLayout 的第二个子项
  • @pskink 也试过了,同时保持高度和宽度为match_parent。尽管如此,vOverlay 还是没有出现。
  • @Mrinali 查看我修改后的评论

标签: android xml android-layout android-relativelayout


【解决方案1】:

用 FrameLayout 替换外部的 RelativeLayout 并将您的叠加层移动到该 FrameLayout 的第二个孩子

【讨论】:

    猜你喜欢
    • 2014-05-17
    • 2014-03-16
    • 1970-01-01
    • 1970-01-01
    • 2013-08-20
    • 2013-05-08
    • 2014-04-21
    • 1970-01-01
    • 2010-12-21
    相关资源
    最近更新 更多