pot34731
pot34731

Reputation: 191

setBackgroundDrawableResource setScaleType(android)

Sorry for my english, i want set background layout image only use getWindow(), like this:

getWindow().setBackgroundDrawableResource(R.drawable.bg_image);

And in bg_image

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <bitmap

            android:src="@drawable/bg_shkaf" />
    </item>

</layer-list>

but the picture is stretched. How can I stretch proportional to the picture?

Upvotes: 1

Views: 665

Answers (1)

Cody Caughlan
Cody Caughlan

Reputation: 32748

I dont think you can specify a scale-type if you just assign the image to the window background.

What I have done in similar scenarios is wrap my layout in a parent FrameLayout with a child ImageView which does take the scaleType attribute. You then add in all of your existing layout views.

Example:

<FrameLayout>
  <ImageView 
    android:src="@drawable/bg_image"
    android:scaleType="fitCenter" 
    android:layout_height="match_parent"
    android:layout_width="match_parent" />

  <!-- all of your other views here ... -->

</FrameLayout>

Upvotes: 1

Related Questions