【问题标题】:image not resizing in View图像未在视图中调整大小
【发布时间】:2016-10-20 19:53:01
【问题描述】:

我有一个 android 应用程序,它可以从实时网络摄像头提要中加载图片。此图像显示在应用程序中。图像会很好地填满屏幕,但出于某种原因 - 由于一些 Android 更新(应用程序大约 4 岁,问题也很旧......)图像不会调整大小并保持为一个小盒子。

这是我用于图像的 XML 代码:

     <com.test.LoaderImageView

             android:id="@+id/loaderImageView"

             android:layout_width="wrap_content"

         android:layout_height="wrap_content"

        android:layout_gravity="center_horizontal"

        android:adjustViewBounds="true"

        android:scaleType="fitCenter"

        image="http://www.tests.com/webcam.jpg"           />

【问题讨论】:

  • 我可以张贴截图来帮助解决问题

标签: android xml android-layout


【解决方案1】:

尝试将 scaleType 切换为 fitXY 并将宽度/高度切换为 fill_parent

android:scaleType="fitXY"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

这可能会弄乱纵横比。如果这是个问题,但图像剪辑没问题——试试android:scaleType="centerCrop"

您使用的是自定义 ImageView 类,因此请确保 image='..'android:src='...' - 而不是 android:background='...'

SRC:ImageView fills parent's width OR height, but maintains aspect ratio & How to scale an Image in ImageView to keep the aspect ratio

【讨论】:

    【解决方案2】:
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="10dp">
    
    <ImageView android:id="@+id/imageView"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:adjustViewBounds="true"
               android:scaleType="fitCenter"
               android:layout_marginTop="10dp"/>
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多