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.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
If your bitmap is wider than it is tall, use
android:gravity="fill_vertical"
. Otherwise, useandroid:gravity="fill_horizontal"
. This has a similar effect as usingandroid:scaleType="centerCrop"
on anImageView
.If you support multiple orientations, you can create one bitmap XML file in the
drawable-port
folder and the other in thedrawable-land
folder.Using the method described by a.ch worked great for me except I used this scale type which worked much better for what I needed:
Here is a full list of available scale types: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
There is an easy way to do this from the drawable:
your_drawable.xml
The only downside is that if there is not enough space, your image won't be fully shown, but it will be clipped, I couldn't find an way to do this directly from a drawable. But from the tests I did it works pretty well, and it doesn't clip that much of the image. You could play more with the gravity options.
Another way will be to just create an layout, where you will use an
ImageView
and set thescaleType
tofitCenter
.Hope this information helps you achieve what you want.