将图像增大到超出屏幕尺寸

发布于 2024-12-12 17:09:46 字数 136 浏览 1 评论 0原文

我想在屏幕上显示图像,但图像边缘将大于屏幕本身的尺寸。 即,如果最大屏幕宽度为 X,那么我希望图像的宽度为 X +100,最大屏幕高度为 Y,则图像高度为 Y +100。

我希望此选项能够将图像向右/向左移动,并且图像仍然会显示在整个屏幕上。

I want to display an image on the screen but the image edges will be larger than the size of the screen itself.
IE if the maximum screen width is X then I want the width of the image will be X +100 and maximum screen height is Y then the image height is Y +100.

I want this option for the ability to move the image to the right / left and still the image will be shown on the whole screen.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁把谁当真 2024-12-19 17:09:46

为此,我使用 RelativeLayoutrequestLayout 函数:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent">

  <ImageView
      android:id="@+id/iv"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"/>

</RelativeLayout> 

并在代码中生成适当的图像:

    Display display = getWindowManager().getDefaultDisplay(); 
    int     width   = display.getWidth();
    int     height  = display.getHeight();

    // example code with bigger dimensions than the screen

    Bitmap b =  Bitmap.createBitmap(width + 100, height + 100, Bitmap.Config.ARGB_8888);

    // draw smth on the bitmap

    Canvas c = new Canvas(b);
    Paint  p = new Paint();

    p.setColor(Color.RED);

    c.drawCircle(b.getWidth() / 2,
                 b.getHeight() / 2,
                 Math.min(b.getWidth(), b.getHeight()) / 2, 
                 p);

    // set the image
    ImageView iv = (ImageView) findViewById(R.id.iv);
    iv.setImageBitmap(b);

    // call this method to change imageview size
    iv.requestLayout();

For this purpose I use RelativeLayout with requestLayout function:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent">

  <ImageView
      android:id="@+id/iv"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"/>

</RelativeLayout> 

And in the code generate an appropriate image:

    Display display = getWindowManager().getDefaultDisplay(); 
    int     width   = display.getWidth();
    int     height  = display.getHeight();

    // example code with bigger dimensions than the screen

    Bitmap b =  Bitmap.createBitmap(width + 100, height + 100, Bitmap.Config.ARGB_8888);

    // draw smth on the bitmap

    Canvas c = new Canvas(b);
    Paint  p = new Paint();

    p.setColor(Color.RED);

    c.drawCircle(b.getWidth() / 2,
                 b.getHeight() / 2,
                 Math.min(b.getWidth(), b.getHeight()) / 2, 
                 p);

    // set the image
    ImageView iv = (ImageView) findViewById(R.id.iv);
    iv.setImageBitmap(b);

    // call this method to change imageview size
    iv.requestLayout();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文