Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android ImageView: Place image on top

Tags:

android

I have an activity containing only one ImageView. This view should display an image loaded from an URL. I want, that this image will be shown on the top of my screen using the whole screen width. My layout-file:

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

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/overview_bgColor" >
        <ImageView 
            android:id="@+id/overview_image"
            android:contentDescription="image"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top|fill_horizontal"/>
    </LinearLayout>

But the image is always shown vertically centered. But why? I thought, that top will place this ImageView on top of my screen?

like image 722
paul_schaefer Avatar asked Sep 01 '25 02:09

paul_schaefer


1 Answers

try this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/overview_bgColor" >
    <ImageView 
        android:id="@+id/overview_image"
        android:contentDescription="image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"            
     />
</LinearLayout>
like image 59
TootsieRockNRoll Avatar answered Sep 04 '25 18:09

TootsieRockNRoll