【问题标题】:Show image in rectangle? [closed]以矩形显示图像? [关闭]
【发布时间】:2014-04-16 21:36:53
【问题描述】:

我想在倾斜到 90 度的矩形中显示图像。我该怎么做?

在这个框架中我想显示图像

请给我一些解决方案。

谢谢。

【问题讨论】:

  • 我看到一个正方形。倾斜 45°...
  • @BobMalooga 正方形是矩形的子类 :)
  • @Ahmad Dwaik 'Warlock':当然。但准确地说(天哪!我专业变形了!!)... ;)
  • @BobMalooga 和我忘了角度,你说的是 45。

标签: android imageview


【解决方案1】:

您可以创建一个 45d 动画并将其应用到您的 ImageView,如下所示:

    ImageView image= (ImageView)findViewById(R.id.imageView);
    // Create 45d animaion
    Animation an = new RotateAnimation(0.0f, 45f, image.getPivotX(), image.getPivotY());

    // Set the animation's parameters
    an.setDuration(1);               
    an.setRepeatCount(0);                
    an.setRepeatMode(Animation.REVERSE); 
    an.setFillAfter(true);               

    // Aplly animation to image
    image.setAnimation(an);

【讨论】:

    【解决方案2】:

    使用 API >= 11

    mImageView.setRotation(angle) 
    

    另一种方法:

    ImageView img = (ImageView)findViewById(R.id.yourImageViewId);
    Options o = getSize(this, R.drawable.yourImage);
    Matrix m = new Matrix();
    m.postRotate(angle, o.outWidth/2, o.outHeight/2);
    img.setScaleType(ScaleType.MATRIX);
    img.setImageMatrix(m);
    

    【讨论】:

      【解决方案3】:

      使用下面的方法。

      public static Bitmap rotate(Bitmap src, float degree) {
          // create new matrix
          Matrix matrix = new Matrix();
          // setup rotation degree
          matrix.postRotate(degree);
      
          // return new bitmap rotated using matrix
          return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
      }
      

      【讨论】:

        【解决方案4】:

        适用于所有 API 将 ImageView 放置在您的 Layout XML 中,并在您的 Activity 的 onCreate() 中为其设置动画:

        float rotationDegree = -45; //You can change if you need.
                Animation anim = new RotateAnimation(0,rotationDegree);
                anim.setFillAfter(true);
                imageView.startAnimation(anim);
        

        【讨论】:

          猜你喜欢
          • 2019-05-24
          • 2012-10-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-06-09
          相关资源
          最近更新 更多