Michel Bourgeois Michel Bourgeois - 3 months ago 9
Android Question

Align Image View to top of the screen in a linear layout

I'm trying to align an image image with space at top of pictureat the top of a Linear Layout in android studio.I have a space as you can see on the picture. I would like to get rid of that space. Tried few things without success!!! Anyone has a clue how to do it??? Thanks

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.bourgeois.michel.relativesinglescreenapp.MainActivity">

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

<ImageView
android:id="@+id/toppicture"
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="@drawable/danielarias" />

<TextView
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:textColor="#ff6600"
android:textStyle="bold"
android:paddingLeft="10dp"
android:text="Phone"/>


<TextView
android:id="@+id/number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textColor="#000"
android:textStyle="normal"
android:text="424-278-8938"/>


<View
android:id="@+id/line"
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="10dp"
android:background="#ff6600"/>
</LinearLayout>

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



<TextView
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/text"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:textColor="#000"
android:textStyle="bold"
android:text="Address: 5867 W 3rd St, Los Angeles, CA 90036"

/>

<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/button"
android:fontFamily="sans-serif-condensed"
android:paddingBottom="1dp"
android:textAlignment="center"
android:textColor="#000"
android:textSize="16sp"
android:text="Learn How To Dance Milonguero Tango Style!"/>

<TextView
android:id="@+id/thursday"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:paddingBottom="5dp"
android:textAlignment="center"
android:textColor="#000"
android:textSize="16sp"
android:text="Every Thursday Night"/>
<TextView
android:id="@+id/hour"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:paddingBottom="5dp"
android:textAlignment="center"
android:textColor="#000"
android:textSize="16sp"
android:text=" 8:30pm to 9:30pm"/>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="15dp"
android:text="Join Us" />





Answer

Use your ImageView like :

<ImageView
    android:layout_width="match_parent"
    android:layout_height="300dp"  
    android:scaleType="fitXY"/>