【问题标题】:Is it possible to display original image in android without fit to device views?是否可以在不适合设备视图的情况下在 android 中显示原始图像?
【发布时间】:2015-07-22 19:40:36
【问题描述】:

我有一个大小为 1000px*1200px 的图像,我希望它在不被缩放的情况下显示!。

我已经在 stackover flow 和 google 中进行了搜索,但我没有得到好的结果。

我想要没有缩放的完整图像, 我试过这样

第一步:-

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image"
                />

第二步:-

我也试过 scaleType 将 scaleType 添加到您的 ImageView

 <ImageView
    android:scaleType="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/image" />

但这也行不通,

在 sclate 类型中,我尝试了所有可能的属性(矩阵、fitXY 像这样)。

有没有可能在android中显示原始图像?

请帮帮我

【问题讨论】:

  • 您是否尝试将该图像存储在 drawable-nodpi 中而不是在 imageview 中设置?
  • 试试 android:scaleType="center" 可能对你有帮助。
  • @Ravi 我已经尝试过 scaletype=center,但不起作用
  • 你能展示一些快照吗,你到底想要什么?
  • @keshav 我想要完整的图像实际图像 1000*1200 大小,所以我希望设备中的图像也具有自动滚动功能。

标签: android image imageview image-scaling


【解决方案1】:

您可以尝试这种方法,首先从drawable中获取图像并创建位图。然后获取位图的宽度和高度,调整图像视图的大小,然后在其中显示图像。它将创建具有原始图像大小的图像视图。

见下面的代码-

BitmapDrawable bitmap = (BitmapDrawable) this.getResources().getDrawable(R.drawable.icon);
int bitmapHeight= bitmap .getBitmap().getHeight();
int bitmapWidth = bitmap .getBitmap().getWidth();

现在您有了原始图像的尺寸。 调整图像视图的大小 -

    ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
    imageView.getLayoutParams().height = bitmapHeight;
    imageView.getLayoutParams().width = bitmapWidth;

并在最后一步将位图设置为您的图像视图 -

imageView.setImageBitmap(bitmap);

希望对你有所帮助。

已编辑

在调整图像视图大小后使用下面的代码 -

replace - `imageView.setImageBitmap(bitmap);`

           imageView.setImageResource(R.drawable.icon);

【讨论】:

  • 那卷轴呢?
  • 哪个卷轴??解释一下?
  • :) .检查我的答案。如果需要,他需要在屏幕小于图像的设备上处理图像滚动
  • getDrawable() 已被贬低,因此在 setImageBitmap() 中显示错误。
  • 不,没有贬低。你遇到什么错误,请分享错误日志。
【解决方案2】:

你的cmets,我想你需要一个像PhotoView这样的库。希望它可以帮助你

【讨论】:

    【解决方案3】:

    虽然我会强烈谴责这样的用户体验,但不管对你有用。

    1) 使用以下链接制作二维卷轴。 Two dimensional scrolling... a suggestion that needs feedback

    2) 添加一个 imageview 并在运行时以 px 为单位设置 imageview 的图像尺寸。

    【讨论】:

      【解决方案4】:

      据我了解,您的问题是您想要图像的自然大小而不需要 ImageView 标记对其进行修改。这对我有用

      <LinearLayout
          android:id="@+id/background"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@drawable/image_here"
          android:orientation="horizontal|vertical"/>
      

      在 cmets 中告诉我。

      【讨论】:

      • 这怎么可能?
      • 为我工作。对我来说唯一的事情是,如果我使用 ImageView 并且宽度为 match_parent,图像将显示在活动中间,在应用程序栏和图像之间留下空白。通过使用 LinearLayout 我可以做我想做的事。你可以试试这个,看看它是否符合你的要求。
      • 在活动中我不需要任何东西。我将用我的活动截图编辑答案
      • 那是我使用 LinearLayout 的形象(在史蒂夫·乔布斯之后)
      • 这绝对行不通,因为 iamge 的最大宽度仍然是屏幕的宽度,而不是它自己的宽度
      【解决方案5】:

      使您的图像布局宽度和高度以包裹内容。使 scaleType 居中。通过设备管理器检查您的设备宽度和高度,然后以 % 为单位提供图像高度和宽度

      【讨论】:

      • 我不想给出静态的高度和宽度,我想动态滚动图像。
      • 只是建议好的。您可以在 scrollView 中像往常一样使用(窗口管理器)和高度(包装内容)将图像宽度设置为 90%。
      【解决方案6】:

      经过多次尝试,我找到了解决上述问题的方法。

      代码如下:

      MainActivity:-

      public class MainActivity extends ActionBarActivity {
      
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
      
              setContentView(R.layout.activity_main);
      
              ImageView imageView = (ImageView) this.findViewById(R.id.imageview);
         }
      }
      

      activity_main.xml:-

      <?xml version="1.0" encoding="utf-8"?>
      <ScrollView android:id="@+id/ScrollView02"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:scrollbars="none"
          xmlns:android="http://schemas.android.com/apk/res/android">
          <HorizontalScrollView android:id="@+id/HorizontalScrollView01"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content">
              <ImageView android:id="@+id/imageview"
                  android:src="@drawable/desert"
                  android:layout_height="wrap_content"
                  android:layout_width="wrap_content"
                  android:adjustViewBounds="true">
              </ImageView>
          </HorizontalScrollView>
      </ScrollView>
      

      这完全符合我的要求。

      希望这对其他人有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多