Issue
How do I make a background image fit the view but keep its aspect ratio when using <bitmap />
as a background drawable XML?
None of <bitmap>
's android:gravity
values gives the desired effect.
Solution
It is impossible to achieve manipulating background attribute within xml-files only. There are two options:
You cut/scale the bitmap programmatically with
Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)
and set it as someView
's background.You use
ImageView
instead of background placing it as the first layout's element and specifyandroid:scaleType
attribute for it:<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/backgrnd" android:scaleType="centerCrop" /> ... rest layout components here ... </RelativeLayout>
Answered By - a.ch.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.