位图剪辑?
所以我想将这个位图用作视图的背景,但位图有时可能比视图大。
假设我的位图是 500x500 像素 当我将位图设置为视图的背景时,我的视图为 200x200px
,视图被拉伸到位图的大小(500x500)...
我尝试将重力设置为 Clip_horizontal|clip_vertical 但这没有帮助...
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/old_wall"
android:tileMode="repeat"
android:gravity="top|left|clip_horizontal|clip_vertical" />
如何让位图被剪切而不是视图被拉伸到位图的大小?
so I have this bitmap I want to use as background on a view, but the bitmap might sometimes be bigger than the view.
let's say my bitmap is 500x500 px
and my view is 200x200px
when I set the bitmap as background for the view, the view get's stretched to the size of the bitmap(500x500)...
I tried setting the gravity to clip_horizontal|clip_vertical but that didn't help...
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/old_wall"
android:tileMode="repeat"
android:gravity="top|left|clip_horizontal|clip_vertical" />
how can I get the bitmap to get clipped instead of the view being stretched to the size of the bitmap?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您始终可以在代码中剪辑原始位图。然后将其设置到视图中。其中 x,y 是起点,
X_WIDTH
、Y_HEIGHT
是终点。iv
是您的目标ImageView
:You can always clip your original bitmap in code. Then set it to the view. Where x,y are your starting points and
X_WIDTH
,Y_HEIGHT
is your ending point. Andiv
is your targetImageView
: