Android LinearLayout 背景图片
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23183705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android LinearLayout background Image
提问by user3141985
I'm having a problem with my view if I try to display an image as background, it took the whole space and the second child of linear layout (2 RelativeLayout that appears next to each other) does not appear into view.
如果我尝试将图像显示为背景,我的视图就会出现问题,它占用了整个空间,并且线性布局的第二个子项(2 个彼此相邻的相对布局)不会出现在视图中。
How can I set image as background keeping other layout elements above it ?
如何将图像设置为背景,并在其上方保留其他布局元素?
<?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>
回答by user3141985
It is a bit late, but my problem was solved with the following code.
有点晚了,但我的问题已通过以下代码解决。
Used the ImageView
to set my background image and then displayed the linear layout over it.
使用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>
If some one needs to know more, I will update the answer.
如果有人需要了解更多,我会更新答案。
Thanks.
谢谢。
回答by Sebastien Bianchi
Use android:background
in your LinearLayout
使用android:background
您的LinearLayout
回答by greywolf82
You have to use android:background
property instead having an ImageView
.
您必须使用android:background
属性而不是ImageView
.