代码之家  ›  专栏  ›  技术社区  ›  Catalin Morosan

在整个屏幕上旋转图像

  •  2
  • Catalin Morosan  · 技术社区  · 14 年前

    我似乎无法在整个屏幕上正确地旋转图像。问题是,当图像旋转时,您可以在某些区域看到背景。我希望图像在旋转时也能填满屏幕。这是布局图。我尝试过不同的比例类型,但没有成功。

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <ImageView
            android:id="@+id/image"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="centerCrop" />
    </LinearLayout>
    

    这是我使用的代码。

    image = (ImageView) findViewById(R.id.image);
    image.setBackgroundResource(R.drawable.back_big);
    rot = AnimationUtils.loadAnimation(this, R.anim.rotation);
    image.startAnimation(rot);
    

    我开始动画在 onResume . 如我所说,图像旋转,但旋转时有背景区域。我试过使用比屏幕大得多的图像,但它仍然不能满足我的需要。我不在乎图像的外部区域是不可见的。我只想让旋转填充屏幕。我猜 ImageView 首先设置其宽度和高度,然后在旋转时使用这些尺寸。有更好的方法吗?

    2 回复  |  直到 14 年前
        1
  •  0
  •   Cheryl Simon    14 年前

    您正在将ImageView的scaleType设置为“CenterCrop”。不幸的是,对于不同scaleType的确切含义没有很好的文档,但是名称意味着图像集中在屏幕上,并被剪切到ImageView的准确大小。因此,当您开始旋转时,您将看到背景区域。

    尝试将scaleType转换为“中心”。

        2
  •  0
  •   Catalin Morosan    14 年前

    在更多地研究了这个问题之后,我认为不可能实现我想要的。如果可能的话,那就太复杂了,不值得。