旋转ImageView的和不cropp背景 [英] Rotating imageview and its background without cropp
本文介绍了旋转ImageView的和不cropp背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在寻找了很多,但我不能让我的问题的解决方案。因为我想这个程序下11版与Android兼容的API轮换:我不能使用Android。
我的问题是类似这样:在android系统旋转视图
I've been searching a lot, but I can't get a solution for my problem. I can't use android:rotation as I want this app to be compatible with Android API under 11 version. My problem is something similar to this: Rotating a view in android
我已经做到了这一点:
@Override
public void draw(Canvas canvas)
{
canvas.save();
Drawable d = getDrawable();
canvas.rotate(-10, d.getIntrinsicWidth()/2, d.getIntrinsicHeight()/2);
super.draw(canvas);
canvas.restore();
}
该ImageView的是一个相对的布局,我放置图像和一些文本的一部分。
The imageView is part of a relative layout where I place the image and some text.
但图像的边缘裁剪。我怎样才能避免?
But the image is cropped in the edges. How can I avoid that?
推荐答案
您只需添加:
android:clipChildren="false"
父的ViewGroup
。
例如:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:clipChildren="false">
<com.yourcompany.views.RotateImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/white"
android:src="@drawable/ic_launcher" />
</FrameLayout>
RotateImageView:
RotateImageView:
public class RotateImageView extends ImageView {
@Override
public void draw(Canvas canvas) {
canvas.save();
int height = canvas.getHeight();
int width = canvas.getWidth();
canvas.rotate(45, height / 2, width / 2);
super.draw(canvas);
canvas.restore();
}
}
哪个API等级11
Which provides a clean solution before API Level 11
这篇关于旋转ImageView的和不cropp背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文