user6827
user6827

Reputation: 1596

ImageView placement not correct

I'm trying to load an image from the internet and put it in an ImageView, but I want to use the screens width as the width for the image and keep the aspect ratio. I've tried all the solutions here on stackoverflow, but it does not help. I think because i'm loading the image afterwards from the internet and put it into the ImageView.

Here is the xml file.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    tools:context=".ViewPhoto"
    android:background="@color/darkgrey"
    android:id="@+id/layout"
    >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:id="@+id/title" 
        android:background="@color/Black"
        android:typeface="sans"
        android:textColor="@color/White"
        />

    <ImageView 
        ??

        />

     <ListView
        android:id="@+id/comments"
        android:layout_below="@+id/photo"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:divider="#b5b5b5"
        android:dividerHeight="2dp"               
        />

</RelativeLayout>

Upvotes: 0

Views: 84

Answers (2)

Abhijit Chakra
Abhijit Chakra

Reputation: 3234

Try using android:scaleType="centerCrop" inside your ImageView.

Upvotes: 0

Blackbelt
Blackbelt

Reputation: 157447

   <ImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:layout_below="@id/title"
    />

try in this way

Upvotes: 1

Related Questions