gpt4 book ai didi

java - relativeLayout背景图片+颜色

转载 作者:行者123 更新时间:2023-12-01 15:43:25 27 4
gpt4 key购买 nike

我有一个RelativeLayout,我需要一个黑色背景和一个位于其中间的小图像。我使用了这段代码:

  <RelativeLayout
android:id="@+id/bottomBox"
android:layout_weight="4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bottom_box_back"
android:layout_marginTop="4dp"
/>

其中@drawable/bottom_box_back是:

<bitmap 
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/logo_icon"
android:tileMode="disabled"
android:gravity="center"
android:filter="true"
/>

这样我就可以将图像居中了。但背景仍然与主窗口一样是灰色的。我需要一个黑色的背景来覆盖整个 RelativeLayout 空间的图像。有什么建议吗?

最佳答案

我会将您的RelativeLayout的背景设置为黑色,然后将图像放入ImageView中并将其居中在RelativeLayout的中间,因此:

<RelativeLayout
android:background="@color/yourBlackColor">

<ImageView
android:layout_centerInParent="true">
</ImageView>

</RelativeLayout>

希望这对你有帮助

关于java - relativeLayout背景图片+颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7611126/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com