/ / ImageView scaleType nie działa - Android, widok obrazu, scaletype

ImageView scaleType nie działa - Android, widok obrazu, scaletype

Mam ImageView, który zawiera trochę "?"jak obraz, ten obraz jest rozciągnięty i wygląda brzydko." "Próbowałem ustawić właściwość ImageView.ScaleType na fitCenter, ale nie ma to żadnego efektu. Próbowałem również wszystkich innych scaleTypes, ale nie wpływa to na mój układ. Ponieważ użytkownik będzie mógł później przesłać obraz o dowolnej wielkości w tym ImageView, chcę, aby mój ImageView zawsze mieścił się w środku. Oto mój plik xml:

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="vertical">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">

<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:background="@android:drawable/ic_menu_save"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="name of question"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>

<ImageView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:id="@+id/imageViewQuestion"
android:layout_gravity="center_horizontal"
android:background="@android:drawable/ic_menu_help"
android:layout_weight="1"
android:cropToPadding="false"
android:onClick="clickQuestion"
android:scaleType="centerCrop" />

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textViewQuestion"
android:layout_gravity="center_horizontal"
android:layout_weight="0.11"
android:textAlignment="center"
android:hint="Question"
android:onClick="clickQuestion"
android:gravity="center" />

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.60">

<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="1"
android:id="@+id/button1"
android:layout_weight="2"
android:onClick="clickButtonEdit" />

<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="2"
android:id="@+id/button2"
android:layout_weight="2"
android:onClick="clickButtonEdit" />

<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="3"
android:id="@+id/button3"
android:layout_weight="2"
android:onClick="clickButtonEdit" />

<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="4"
android:id="@+id/button4"
android:layout_weight="2"
android:onClick="clickButtonEdit" />
</LinearLayout>

</LinearLayout>

Czy ktoś widzi mój błąd?

Odpowiedzi:

24 dla odpowiedzi № 1

Spróbuj użyć src zamiast background :

zastąpić

android:background="@android:drawable/ic_menu_help"

przez

android:src="@android:drawable/ic_menu_help"