[英]How can I prevent Android from cropping my ImageView?
I have an ImageView, which will fill the entire width of the screen and will also be animated up and down like a wave at the bottom of the screen. 我有一个ImageView,它将填充屏幕的整个宽度,并且还将像在屏幕底部的波浪一样上下动画。 I have used scaleType="matrix" since it should not stretch to fit within the screen.
我使用了scaleType =“ matrix”,因为它不应该拉伸以适合屏幕。
However, once it has been layouted, Android crops everything away that was outside at the time of layout-update, so once it starts to animate the bottom part is missing. 但是,一旦进行了布局,Android就会在布局更新时将外部的所有内容都裁剪掉,因此一旦开始为底部进行动画处理,就会丢失。
So my question is, how can I prevent Android from cropping my ImageView? 所以我的问题是,如何防止Android裁剪ImageView?
I wrote a class that seems to solve the problem, thought I´d share it if someone else faces this problem.. 我写了一个看来可以解决问题的课程,以为如果其他人遇到这个问题,我也会分享。
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ImageView;
public class NoCropImageView extends ImageView
{
private int fixedWidth = 0;
private int fixedHeight = 0;
private int[] attrsArray = new int[] { android.R.attr.layout_width, android.R.attr.layout_height };
public NoCropImageView(final Context context, final AttributeSet attrs)
{
super(context, attrs);
TypedArray ta = context.obtainStyledAttributes(attrs, attrsArray);
int layout_width = ta.getDimensionPixelSize(0, ViewGroup.LayoutParams.MATCH_PARENT);
int layout_height = ta.getDimensionPixelSize(1, ViewGroup.LayoutParams.MATCH_PARENT);
ta.recycle();
fixedWidth = layout_width;
fixedHeight = layout_height;
}
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec)
{
this.setMeasuredDimension(fixedWidth, fixedHeight);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.