Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: can't remove vertical gap between images in LinearLayout

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?

like image 411
Enrico Detoma Avatar asked Aug 31 '10 17:08

Enrico Detoma


People also ask

What is RelativeLayout in android?

RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).

What is the default value of the orientation attribute in LinearLayout?

android:orientation Use "horizontal" for a row, "vertical" for a column. The default is horizontal.

Why use Constraint layout?

Advantages of using ConstraintLayout in AndroidIt helps to improve the UI performance over other layouts. With the help of ConstraintLayout, we can control the group of widgets through a single line of code. With the help of ConstraintLayout, we can easily add animations to the UI components which we used in our app.

What does layout weight do?

Layout Weight This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view.


2 Answers

I found the solution. I needed to add this attribute to the ImageView:

android:adjustViewBounds="true" 
like image 117
Enrico Detoma Avatar answered Sep 27 '22 16:09

Enrico Detoma


add android:scaleType="fitXY" in xml layout.

like image 40
RaviPatidar Avatar answered Sep 27 '22 18:09

RaviPatidar