2013-04-24 48 views
0

我試圖從網絡上載入圖像並將其放入ImageView,但我想使用屏幕寬度作爲圖像寬度並保持寬高比。我在這裏嘗試了所有的解決方案,但它沒有幫助。我想因爲我從互聯網上載入圖像並將其放入ImageViewImageView展示位置不正確

這是xml文件。

<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> 
+0

你沒有得到適當的長寬比嗎? – 2013-04-24 10:19:06

回答

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

嘗試以這種方式

+0

現在寬度不是屏幕寬度,當我使用'android:layout_width =「fill_parent」'時,高度不再正確。非常奇怪 – user6827 2013-04-24 11:04:30

0

嘗試使用android:scaleType="centerCrop"ImageView內。

+0

現在寬度不是屏幕寬度,當我使用'android:layout_width =「fill_parent」'時,高度不再正確。 – user6827 2013-04-24 11:19:40

+0

什麼是您的設備的dpi和什麼是您的圖像的分辨率。 – 2013-04-24 11:21:34

+0

我的dpi是320,分辨率256×192 – user6827 2013-04-24 11:25:38