我是 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>
此处截图(见右侧预览):
最佳答案
这些额外的填充是自动生成的,因为 android 会尝试获得原始的纵横比。请尝试以下
scaletype = "fitCenter"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
关于android - ImageView 中不需要的填充或边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42363875/