The 29th Saltshaker
The 29th Saltshaker

Reputation: 691

How do I display an ImageView underneath the middle of a LinearLayout?

So in my XML I have a LinearLayout

<LinearLayout ...>
 ...
</LinearLayout>

But I want to display an ImageView in the background of the LinearLayout, in the center, behind everything. How can I do this?

Upvotes: 0

Views: 227

Answers (2)

Zamrony P. Juhara
Zamrony P. Juhara

Reputation: 5262

Add FrameLayout to contain ImageView and LinearLayout, something like this:

<FrameLayout 
    android:layout_width = "fill_parent"
    android:layout_height = "fill_parent" >
    <ImageView 
        android:src = "@drawable/your_own_image"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_gravity= "center" />
    <LinearLayout>
    ...
    <LinearLayout> 
</FrameLayout>

FrameLayout will display child views from the first view to last. So ImageView will be display behind LinearLayout.

Upvotes: 1

BlackHatSamurai
BlackHatSamurai

Reputation: 23513

You can do something like

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/my_drawable"
    android:scaleType="fitCenter"
    />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
</LinearLayout>

</FrameLayout>

Upvotes: 0

Related Questions