image not resizing in View

时间:2016-10-20 19:53:01

标签: android xml android-layout

I have an android app that loads a picture from a live webcam feed. This image is displayed within the app. The image would fill the screen nicely but for some reason - because of some Android update (App is about 4 years old and problem is old also..) the image does not resize and remains as a small box.

This is the XML code I use for the image:

     <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"           />

2 个答案:

答案 0 :(得分:0)

尝试将scaleType切换为fitXY&amp;宽度/高度为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

答案 1 :(得分:0)

<?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>
相关问题