Maksymalna szerokość i wysokość dla ImageView w systemie Android

Więc mam zestaw ImageView z

android:maxHeight="100px"
android:maxWidth="250px"
android:minHeight="100px"
android:minWidth="250px"
android:scaleType="centerInside"

Ten widok obrazu jest używany do wyświetlania obrazu uzyskanego z galerii lub kamery. W obu przypadkach obraz nie jest zmieniany, aby zmieścił się w widoku imageview, po prostu rozciąga swoją przestrzeń tak bardzo, jak potrzebuje.

Jakiś pomysł, jak sprawić, by pozostała w tych granicach?
<?xml version="1.0" encoding="utf-8"?>

<EditText
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:id="@+id/txtDescription"
    android:layout_below="@+id/txtSubject"
    android:inputType="textMultiLine"
    android:height="80px"
    android:hint="@string/description"></EditText>

<EditText
    android:layout_height="wrap_content"
    android:layout_below="@+id/txtDescription"
    android:layout_width="fill_parent"
    android:id="@+id/txtMorada"
    android:hint="@string/address" />

<ImageButton
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_below="@+id/txtMorada"
    android:id="@+id/btGPS"
    android:layout_alignParentLeft="true"
    android:src="@drawable/ic_menu_compass"></ImageButton>

<ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_below="@+id/btGPS"
    android:layout_marginTop="25px"
    android:id="@+id/imgPoint"
    android:src="@drawable/google_logo_small"
    android:maxHeight="100px"
    android:maxWidth="250px"
    android:minHeight="100px"
    android:minWidth="250px"
    android:scaleType="centerInside"></ImageView>

<ImageButton
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_toRightOf="@+id/imgPoint"
    android:id="@+id/btGallery"
    android:layout_below="@+id/btCamera"
    android:src="@drawable/ic_menu_gallery"
    android:layout_alignParentRight="true"></ImageButton>

<Button
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_marginTop="10px"
    android:id="@+id/btSubmit"
    android:layout_below="@+id/btGallery"
    android:text="@string/submit"></Button>

<ImageButton
    android:layout_height="wrap_content"
    android:id="@+id/btMap"
    android:layout_below="@+id/txtMorada"
    android:layout_width="wrap_content"
    android:layout_alignParentRight="true"
    android:src="@drawable/ic_menu_mapmode"></ImageButton>

<TextView
    android:layout_below="@+id/txtMorada"
    android:layout_width="wrap_content"
    android:layout_toLeftOf="@+id/btMap"
    android:layout_height="wrap_content"
    android:id="@+id/lblNewPointLatitude"
    android:text="Latitude"></TextView>

<TextView
    android:layout_width="wrap_content"
    android:layout_toLeftOf="@+id/btMap"
    android:layout_height="wrap_content"
    android:id="@+id/lblNewPointLongitude"
    android:layout_below="@+id/lblNewPointLatitude"
    android:text="Longitude"></TextView>

<ImageButton
    android:layout_below="@+id/btMap"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_toRightOf="@+is/imgPoint"
    android:id="@+id/btCamera"
    android:layout_marginTop="25px"
    android:src="@drawable/ic_menu_camera"
    android:layout_alignParentRight="true"></ImageButton>

<Spinner
    android:layout_height="wrap_content"
    android:id="@+id/spCategoria"
    android:layout_width="fill_parent"
    android:prompt="@string/spCategoriaPrompt"></Spinner>

<Spinner
    android:layout_height="wrap_content"
    android:id="@+id/spSubcategoria"
    android:layout_below="@+id/spCategoria"
    android:layout_width="fill_parent"
    android:prompt="@string/spSubcategoriaPrompt"></Spinner>

<EditText
    android:layout_height="wrap_content"
    android:layout_below="@+id/spSubcategoria"
    android:layout_width="fill_parent"
    android:id="@+id/txtSubject"
    android:hint="@string/subject"></EditText>

  </RelativeLayout>
</ScrollView>
Author: Jonik, 2010-11-24

4 answers

Spróbuj adjustViewBounds atrybut:

android:adjustViewBounds="true"
 208
Author: Pedro Loureiro,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-09-04 16:48:31

Masz zarówno layout_width jak i layout_height ustawione na wrap_content, oprócz ustawiania jawnych wartości dla szerokości i wysokości. Zamiast tego powinieneś ustawić layout_width i layout_height na pewną wartość liczbową. Użyj również dp zamiast px. Zobacz Obsługa wielu rozmiarów ekranu .

 7
Author: Cheryl Simon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-24 19:19:44

Czy próbowałeś android: scaleType= "fitCenter" ? Również wymiary widoku nie powinny być ustawione na wrap_content, jak wskazuje Mayra

 6
Author: Asahi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-11-24 19:26:03

Spróbuj włączyć to: xmlns:android="http://schemas.android.com/apk/res/android" Przykład:

<ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxHeight="400dp"
    android:adjustViewBounds="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:src="@drawable/background_img"
    />
 1
Author: Satish Rajbhar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-15 21:10:06