使用ImageView的背景为一个Android布局 [英] Using ImageView as background for an Android Layout
问题描述
我想借此scaleType属性的,而如果我使用的的LinearLayout
背景属性设置我的形象,我不能使用的优势。我用尝试了的LinearLayout
有2个孩子:第一个是的ImageView
(背景图像)和第二个孩子是另一个的LinearLayout
包含 TextViews
,按钮等,但结果却图像其次是其他视图。
I want to take advantage of the scaleType property, which I cannot use if I set my image using the background property on the LinearLayout
. I've tried using a LinearLayout
with 2 children: the first is an ImageView
(for the background image) and the second child is another LinearLayout
containing TextViews
, Buttons, etc. But the result is just the image followed by the other views.
是否有可能飘起了嵌套的的LinearLayout
在的ImageView
不知何故?我知道有很多周围的变化对这个问题,但我还没有发现,帮助我还没有任何东西。如果我错过了什么,请点我在那个方向。另外,我想如果可能的话,为此在XML,我灵活的约,我可以使用什么类型的布局(它不具有线性)。
Is it possible to float the nested LinearLayout
over the ImageView
somehow? I know that there's lots of variations on this question around, but I haven't found anything that's helped me yet. If I've missed something, please point me in that direction. Also, I'd like to do this in XML if possible, and I'm flexible about what type of layout I can use (it doesn't have to Linear).
推荐答案
我做到了,正是如此使用RelativeLayout的为母:
I did it thusly using a RelativeLayout as the parent:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#000000" >
<ImageView
style="@style/BackGroundImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp"
tools:ignore="ContentDescription" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
//Rest of widgets......
我的风格吧:
My Style for it:
<style name="BackGroundImageView">
<item name="android:alpha">0.5</item>
<item name="android:scaleType">fitXY</item>
<item name="android:src">@drawable/img_background</item>
</style>
我用一种风格,因为阿尔法设置不低于上工作的API(不记得什么限制为副手)。
I used a style, because the alpha setting doesn't work on lower APIs (can't remember what the limit is offhand).
这篇关于使用ImageView的背景为一个Android布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!