图像视图不包装内容

Tyl*_*ian 61 java android imageview

我有一个ImageView包装这个图像:

<ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:scaleType="fitStart"
    android:src="@drawable/oncmap"/>
Run Code Online (Sandbox Code Playgroud)

一个TextView,就在它下面.不幸的是,它根据设备的屏幕尺寸将其推向视图或视图外.

http://i.imgur.com/CuVFK5P.png

http://i.imgur.com/6wzMebV.jpg

我可以"破解"它,但它不是......

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="16dp"
android:orientation="vertical"
tools:context="MapFragment">

<ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/oncmap"/>

<TextView
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:text="Neptune"
    style="@style/sectionHeader"/>

<TextView
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="16dp"
    android:text="@string/info"
    style="@style/text"/>
Run Code Online (Sandbox Code Playgroud)

sac*_*n10 207

将以下字段添加到ImageView:

android:scaleType="fitXY"
android:adjustViewBounds="true"
Run Code Online (Sandbox Code Playgroud)

  • scaleType不是真的需要.adjustViewBounds完成这项工作.但有人可以解释为什么会出现这个问题吗? (20认同)
  • adjustViewBounds节省了一天 (11认同)