使用ImageView作为Android布局的背景

RTF*_*RTF 7 android android-layout android-xml android-imageview android-background

我想利用scaleType属性,如果我使用背景属性设置我的图像,我就无法使用它LinearLayout.我尝试过使用LinearLayout2个孩子:第一个是ImageView(用于背景图像),第二个孩子是另一个LinearLayout包含TextViews,按钮等.但结果只是其他视图后面的图像.

是否有可能浮在嵌套LinearLayoutImageView不知何故?我知道这个问题有很多变化,但我还没有发现任何对我有帮助的东西.如果我错过了什么,请指出我的方向.另外,如果可能的话,我想用XML做这件事,而且我可以灵活地使用什么类型的布局(它没有线性).

Ric*_*lck 24

我这样做是因为使用RelativeLayout作为父:

<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......-->

    </LinearLayout>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我的风格:

<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>
Run Code Online (Sandbox Code Playgroud)

我使用了一种风格,因为alpha设置不适用于较低的API(不记得限制是什么).