gpt4 book ai didi

Android LinearLayout背景图片

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:19:59 26 4
gpt4 key购买 nike

如果我尝试将图像显示为背景,我的 View 就会出现问题,它占用了整个空间,并且线性布局的第二个子元素(2 个彼此相邻的 RelativeLayout)没有出现在 View 中。

如何将图像设置为背景,并在其上方保留其他布局元素?

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

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/globe"
android:layout_gravity="top"
/>

</RelativeLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
</RelativeLayout>


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
</RelativeLayout>

</LinearLayout>


</LinearLayout>

最佳答案

有点晚了,但我的问题用下面的代码解决了。

使用 ImageView 设置我的背景图片,然后在其上显示线性布局。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:contentDescription="@string/my_msg"
android:src="@drawable/my_super_bg_image" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/top_style"
android:orientation="vertical" >

<RelativeLayout
android:id="@+id/today"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="some text here"
android:textSize="24sp" />
</RelativeLayout>

</LinearLayout>

</FrameLayout>

如果有人需要了解更多,我会更新答案。

谢谢。

关于Android LinearLayout背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23183705/

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