android - ImageView 中不需要的填充或边距

标签 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>

此处截图(见右侧预览):

1

最佳答案

这些额外的填充是自动生成的,因为 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/

相关文章:

android - 三角形 - 它是如何工作的?

android-studio - 如何在 Google Play 音乐中添加 float Activity ,如 "Now Playing Music"

java - 如何使用自动链接 :phone? 让一个字符串中的多个电话号码可点击

java - 文件提供者 : Failed to find configured root

java - +id 在RelativeLayout 中如何有效?

android - Horizo​​ntalScrollView 中有许多 CardView

java - 如何检查图像质量是否低

android - Eclipse Android XML 在编辑器周围跳跃

java - 我需要使用 ArrayAdapter 在 GridView 中显示 ArrayList<String>

android - 如何在Android中使多个元素水平填充屏幕