Android:无法消除LinearLayout中图像之间的垂直间隙

时间:2010-08-31 17:53:23

标签: android imageview android-linearlayout

我在Android中有一个简单的LinearLayout,它有两个垂直图像:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.eataly.android" 
    android:orientation="vertical"
    android:background="@android:color/white"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/img_header1"
        />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/img_header2"
        />
</LinearLayout>

正如您在以下链接中所看到的,我无法摆脱图像顶部和底部的间隙: http://img185.imageshack.us/img185/8484/senzanomev.png

我已尝试过LinearLayout和ImageViews上可以想到的一切,即:

android:padding="0px"
android:top="0px"
android:bottom="0px"
android:top="0px"
android:layout_margin="0px"

没有成功。 我该怎么做才能删除这些空白边框?

3 个答案:

答案 0 :(得分:66)

我找到了解决方案。我需要将此属性添加到ImageView

android:adjustViewBounds="true"

答案 1 :(得分:3)

添加android:scaleType =&#34; fitXY&#34;在xml布局中。

答案 2 :(得分:0)

在线性布局中执行此操作 对于顶部ImageView:android:gravity="bottom"
对于底部ImageView:android:gravity="top"
您确定不想使用RelativeLayout吗?如果你试图将两张图像相互对齐,那么这就好像是走在路上的方式。

相关问题