ImageView 中不需要的填充或边距

Shi*_*Jha 2 android android-layout android-studio

我对 android 到 android 开发是全新的,只是使用 xml 来构建布局。我编写了以下代码来打印 hello ubuntu 并在其中插入图像。但图像似乎有不需要的上下填充或边距(不确定它叫什么),看起来很奇怪。请任何人帮我删除它。这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:background="@color/colorAccent"
    android:orientation="vertical"
    android:padding="10dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:layout_margin="8dp"
        android:text="Hello Ubuntu (16.06LTS)"
        android:background="@color/colorPrimary"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="0dp"
        android:src="@mipmap/Ubuntu"
        android:layout_margin="0dp"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

截图如下(见右侧预览):

1

MJ *_*tes 5

这些额外的填充是自动生成的,因为 Android 会尝试获取原始的宽高比。请尝试下面

scaletype = "fitCenter"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Run Code Online (Sandbox Code Playgroud)