2012-07-08 101 views
0

我想要調整圖像的大小以適應屏幕,以填充整個寬度。高度應該設置爲高寬比。 例如,圖像尺寸是widthxheight 10x5,手機寬度是400。圖像應該以200x400顯示。Android佈局,縮放到屏幕分辨率的寬度

我有一些設置發揮各地 機器人:scaleType =「中心」應根據文檔正確的設置,但似乎沒有任何效果, 機器人:scaleType =「centerCrop」適合HIGHT,使寬度大於大屏幕。

我的繼承人佈局:

<?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" > 


<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/imageViewFrage" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:adjustViewBounds="true" 
     android:padding="1dp" 
     android:scaleType="centerCrop" 
     android:src="@drawable/bg_striped_img" /> 
</LinearLayout> 

</LinearLayout> 

非常感謝

回答

1

你應該嘗試android:scaleType="centerInside"

根據文檔(http://developer.android.com/reference/android/widget/ImageView.ScaleType.html):

縮放圖像均勻(保持圖像的縱橫比),以使圖像的兩個尺寸(寬度和高度)會比對應的等於或小於視圖的尺寸(減去填充)。圖像然後居中在視圖中。

+0

沒有工作,居中圖像,但使用圖像的寬度和高度。也試過android:layout_width =「match_parent」 android:layout_height =「match_parent」 – user1324936 2012-07-09 17:35:33