【问题标题】:Unexpected space between views in LinearLayoutLinearLayout 中视图之间的意外空间
【发布时间】:2014-02-25 18:26:05
【问题描述】:

我有以下布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:id="@+id/fragment_send_imageView"
        android:layout_margin="0dp"
        android:padding="0dp"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:padding="0dp"
        android:layout_margin="0dp">

        <com.google.android.gms.maps.MapView
            android:id="@+id/fragment_send_mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </RelativeLayout>
</LinearLayout>

在我的设备上是这样的:
如您所见,有两个“分隔线”——一个位于应用程序窗口的顶部边框和 ImageView 之间,第二个位于 ImageView 和 MapView 之间。我已将填充/边距设置为 0 - 不走运。我该怎么办?

【问题讨论】:

  • 为你的图像视图尝试 scaletype = fitxy
  • 这是由于图像而发生的。试试@TamilselvanKalimuthu 的回答

标签: android android-linearlayout spacing


【解决方案1】:

为你的图像视图试试这个

<ImageView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="3"
    android:id="@+id/fragment_send_imageView"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:padding="0dp"/>

【讨论】:

  • 是的,justViewBounds 和(尤其是)scaleType 成功了。我会尽快接受答案。感谢您的帮助!
  • 如果它有效,那么不要忘记在正确的标记上打勾