3

我是新手,所以请原谅我。我已经尝试过搜索文档和一般的互联网,但我无法弄清楚。这是我的 XML:

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

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:contentDescription="@string/desc"
        android:src="@drawable/my_image" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="@string/hello_world"/>
</RelativeLayout>

它看起来像这样:

截屏

我只希望按钮完全不透明,并且看不到背景图像与按钮混合。换句话说,我希望图像位于背景中,并且按钮牢固地显示在其上方。我使用了这两个元素的 alpha 设置,但无法弄清楚。谢谢。

4

3 回答 3

1

尝试将 Button 的背景颜色更改为您想要使用的任何颜色android:background。例如使其红色使用android:background = "#ff0000"

于 2012-10-14T00:45:20.357 回答
0

如果您不想更改按钮的颜色,那么提供的答案是不够的。相反,将按钮放在另一个具有黑色背景的布局中。例如:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:background="@android:color/black" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"/>

</LinearLayout>
于 2013-08-14T01:37:40.333 回答
0

您正在使用相对布局 (clicky)。它是强大的小部件容器,但您需要小心。

对于您指定的按钮layout_centerInParent=true,布局管理器会执行此操作 - 它将您的按钮设置在容器的中心(可能是整个屏幕)

默认情况下,在相对布局中,所有子视图都绘制在布局的左上角,这就是它在那里绘制 ImageView 的原因,您还设置了layout_widthlayout_heightto fill_parent,它会这样做,填充整个容器。

如果您想定位(例如在 ImageView 下方),您需要这样说: android:layout_below="@id/ImageView_ID"在 Button 属性中。

于 2012-10-14T00:19:33.480 回答