问题
I have a simple LinearLayout in Android with two images vertically:
<?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>
As you can see at the following link, I can't get rid of a a gap at the top and at the bottom of the images: http://img185.imageshack.us/img185/8484/senzanomev.png
I've tried everything imaginable on the LinearLayout and the ImageViews, i.e.:
android:padding="0px"
android:top="0px"
android:bottom="0px"
android:top="0px"
android:layout_margin="0px"
with no success. What can I do to remove these empty borders?
回答1:
I found the solution. I needed to add this attribute to the ImageView:
android:adjustViewBounds="true"
回答2:
add android:scaleType="fitXY" in xml layout.
回答3:
To do this in a linearlayout
for the top ImageView: android:gravity="bottom"
for the bottom ImageView: android:gravity="top"
Are you sure you don't want to be using a RelativeLayout? If you're trying to align two images to each other, that seems the way to go for down the road imho.
来源:https://stackoverflow.com/questions/3611769/android-cant-remove-vertical-gap-between-images-in-linearlayout