【问题标题】:Overlay over RelativeLayout doesn't work on images in the layout覆盖在 RelativeLayout 上不适用于布局中的图像
【发布时间】:2014-09-05 11:49:42
【问题描述】:

我有一个带有 textviews 和 imageviews 的 relativeLayout。

当我像这样覆盖布局时:

    color = new ColorDrawable(Color.argb(80, 0, 0, 0));
        mMainLayout.setBackground(color);

布局有一些较深的颜色。

除了它们保持相同的图像视图。所以我想我试试看

 statsImage.setImageAlpha(255);

但图像仍然保持不变。

有人可以帮助我吗?

还有人解释为什么 imageview 没有得到覆盖?它是布局的子元素:

    <ImageView
        android:id="@+id/headerImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/shape_profile_pic" />


    <ImageView
        android:id="@+id/statsImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginTop="70dp"
        android:background="@drawable/shape_stats" />
</RelativeLayout>

编辑:

我现在明白了:

  <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <View
        android:id="@+id/overlayMainView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       />

我这样设置背景颜色:

color = new ColorDrawable(Color.argb(80, 0, 0, 0));
mMainViewOverlay.setBackground(color);

【问题讨论】:

  • mMainLayout.setBackground(color);设置,嗯,背景播种背景如何覆盖前景中的东西?你需要的是一个完全覆盖你的相对布局的视图
  • 所以我只需要在所有内容周围添加一个 并设置背景颜色?
  • 我不能更好地表达它,是的,只需使用普通的 View 并将其背景颜色设置为半透明
  • 发现了问题:)。感谢您的帮助。

标签: android android-layout


【解决方案1】:

找到了解决办法。您需要使用我的编辑中的代码。您只需要在相对布局的末尾添加“黑色”视图,否则您在视图之后添加的所有内容都位于视图之上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-17
    • 2013-01-27
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 2017-02-05
    • 1970-01-01
    相关资源
    最近更新 更多