android:scaleType="fitCenter" 是否仅适用于修复 Layout_width 和 Layout_height 属性?

发布于 2024-09-24 21:37:49 字数 979 浏览 1 评论 0 原文

我使用 Layout_width="fill_parent" 和 Layout_height="wrap content"。如果图像大于 ImageView,它将被完美缩小。

然而,我从来没有成功地放大较小的图像。我尝试了 ScaleType 和“AdjustViewBounds”的任意组合:它总是在图像视图的中间保持其自身的大小。这是代码...

 <LinearLayout
        android:id="@+id/LinearLayout02"
        android:layout_height="wrap_content"
        android:background="@drawable/content_bg"
        android:orientation="vertical"
        android:padding="5dp"
        android:layout_width="fill_parent"
        android:layout_marginLeft="1px">
        <ImageView
          android:layout_height="wrap_content"
          android:src="@drawable/test"
          android:id="@+id/ImageViewTest"
          android:layout_width="fill_parent"
          android:adjustViewBounds="true"
          android:scaleType="center"></ImageView>
</LinearLayout>

I use Layout_width="fill_parent" and Layout_height="wrap content". If an image is bigger than the ImageView, it will be downscaled perfectly.

However, I never got it working to upscale smaller images. I tried any combination of ScaleType and "AdjustViewBounds": it always stays in its own size in the middle of the image view. Here is the code...

 <LinearLayout
        android:id="@+id/LinearLayout02"
        android:layout_height="wrap_content"
        android:background="@drawable/content_bg"
        android:orientation="vertical"
        android:padding="5dp"
        android:layout_width="fill_parent"
        android:layout_marginLeft="1px">
        <ImageView
          android:layout_height="wrap_content"
          android:src="@drawable/test"
          android:id="@+id/ImageViewTest"
          android:layout_width="fill_parent"
          android:adjustViewBounds="true"
          android:scaleType="center"></ImageView>
</LinearLayout>

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

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

发布评论

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

评论(4

假面具 2024-10-01 21:37:49

我刚刚找到了一种让它发挥作用的方法。

这适用于 2.1(AVD) 和 2.1(AVD) 版本。 4.1.2(设备)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitCenter" />

</LinearLayout>

I just found a way to make it work.

This works in 2.1(AVD) & 4.1.2(device)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitCenter" />

</LinearLayout>
旧时浪漫 2024-10-01 21:37:49
<LinearLayout
    android:layout_height="wrap_content"

使用内部图像的原始尺寸。

尝试更大的东西或 fill_parent

<LinearLayout
    android:layout_height="wrap_content"

uses the original size of the image inside.

Try something bigger or fill_parent

浅忆流年 2024-10-01 21:37:49

使用 android:scaleType="FIT_START"android:scaleType="FIT_END" 来计算将保持原始 src 宽高比的比例,但也会确保 src完全适合 dst (来自 GoogleDev)。

更多信息:

http://developer.android.com/reference/android/小部件/ImageView.ScaleType.html

Use android:scaleType="FIT_START" or android:scaleType="FIT_END", to Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst (from GoogleDev).

More info:

http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

谈场末日恋爱 2024-10-01 21:37:49

如果尺寸很小,将 android:scaleType="fitXY" 添加到您的 ImageView 应该会拉伸图像。

Adding android:scaleType="fitXY" to ur ImageView should stretch the image if the size is small.

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