ImageView proportional vergrössen - nur XML ???

  • Antworten:4
Marco S.
  • Forum-Beiträge: 105

28.03.2010, 16:44:30 via Website

Hallo,

ich bin da gerade über etwas gestolpert, was mir etwas Kopfschmerzen bereitet.

Ich habe eine Grafik in 300x98.

Diese möchte ich von der Breite her fill_parent machen, die Höhe soll von Android selber berechnet werden, und dabei soll das ganze auch noch die originale Aspektratio beibehalten.

Um ehrlich zu sein hab ich alle möglichen Kombinationen von android:scaleType und android:adjustViewBounds durch, und nichts scheint da zu passen.

:-(

Die beste Lösung die ich gefunden habe war:

1) hab mit Photoshop mal gerechnet
2) hab das Layout in layout-port und layout-land verschoben
3) im Portrait Mode: android:scaleType="fitXY" android:layout_width="320dip" android:layout_height="105dip"
4) im Landscape Mode: android:scaleType="fitXY" android:layout_width="480dip" android:layout_height="157dip"

Hat jemand eine Idee wie ich das automatisch gestalten kann? Das Problem besteht eigentlich hauptsächlich darin, dass ich zwar android:layout_width="fill_parent" eingeben kann, aber android:layout_height nicht auf "automatisch berechnen" stellen kann.

Gruß
Marco

Antworten
Marco S.
  • Forum-Beiträge: 105

28.03.2010, 16:46:27 via Website

Die Doku hiflt auch nicht wirklich :(

CENTER
Center the image in the view, but perform no scaling.

CENTER_CROP
Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).

CENTER_INSIDE
Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).

FIT_CENTER
Scale the image using CENTER.

FIT_END
Scale the image using END.

FIT_START
Scale the image using START.

FIT_XY
Scale the image using FILL.

MATRIX
Scale using the image matrix when drawing.

Gruß
Marco

Antworten
Markus Gu
  • Forum-Beiträge: 2.644

28.03.2010, 18:00:13 via Website

hmm

ich weiß nicht ganz genau, was du machen willst, aber wenn es sich um ein fixes bild handelt, dann such mal nach 9patch grafiken.

diese grafiken skalieren sich automatisch richtig, wenn sie mehr platz zur verfügung haben.

swordiApps Blog - Website

Antworten
Marco S.
  • Forum-Beiträge: 105

28.03.2010, 19:09:20 via Website

hi,

also ich hab ein listview mit einer row, die aus einem relative layout besteht, worin ein grosses bild (darum gehts ja hier) und ein bisschen text drunter steht.

naja, und das bild lade ich dynamisch aus dem netz (nachdem ich ne menge xml parse usw) - also ist das wandeln in ninepatch nicht drin.

ich will einfach nur dass die grafik die breite der liste minus meinem padding einnimmt.

aber das vergrössern ist echt n problem...

gruß
marco

— geändert am 30.03.2010, 11:13:20

Antworten
Marco S.
  • Forum-Beiträge: 105

30.03.2010, 11:15:12 via Website

ist das nicht zum verrückt werden?

1<?xml version="1.0" encoding="utf-8"?>
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical" android:layout_width="fill_parent"
4 android:layout_height="fill_parent" android:scrollbarStyle="outsideInset">
5
6 <ImageView android:id="@+id/icon" android:scaleType="fitXY"
7 android:adjustViewBounds="true" android:layout_width="fill_parent"
8 android:layout_height="wrap_content" android:src="@drawable/two" />
9
10</LinearLayout>

aus diesem bild:


wird dann das hier.
http://www.anddev.org/files/device_155.png

ich finds krass, dass man nicht so simple sachen wie "proportional vergrössern" mit imageview machen kann...

hat jemand ne idee?

gruß
marco

Antworten