2015-06-22 38 views
0

我有一個從數據庫填充的ImageView(圖像來自數據庫)。在數據庫中我有圖像肖像和風景!我如何調整imageView根據圖像的寬度和高度自行調整它。我嘗試了很多方法,但沒有結果!任何幫助,請!android imageView scale

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <HorizontalScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/slideshow" 
     android:orientation="horizontal" 
     android:padding="0dp" 
     > 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="300dp" 
      android:layout_marginRight="5dp" 
      android:id="@+id/slide1" 
      android:src="@drawable/ddd" 
      /> 
+1

使用'android:layout_width =「wrap_content」android:layout_height =「wrap_content」' –

+0

爲什麼在RelativeLayout裏面有一個LinearLayout? –

+0

使用wrap_content爲relativelayout和imageview – Srijith

回答

1

試試這個代碼。 adjustViewBounds屬性使ImageView與放入其中的圖像尺寸相同。

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:adjustViewBounds="true" /> 

如果您需要特定widthheight改變wrap_content值。

+0

Tanx太多親愛的Max! – Lamiya