2014-09-27 58 views
0

所以我試圖去適應Android,並打算爲美國國家航空航天局的「一天的圖像」RSS提要創建一個應用程序,這本質上需要一個圖像和幾個文本視圖。 這是我在佈局當前的嘗試(編譯爲Android 4.3,如果應該的問題):Android ImageView - 令人討厭的Whitespace在右側

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="com.headfirst.nasaiodt.Feed" > 

    <ImageView 
     android:id="@+id/imgView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scaleType="fitStart" 
     android:adjustViewBounds="true" 
     android:contentDescription="@string/testImgDescription" 
     android:src="@drawable/test_img" /> 

    <TextView 
     android:id="@+id/titleView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/testTitle" /> 

    <TextView 
     android:id="@+id/dateView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/testDate" /> 

    <TextView 
     android:id="@+id/descriptionView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/testContent" /> 

</LinearLayout> 

你會認爲這是它的目的很簡單,但是,我似乎無法擺脫非常耐白條上的圖像的右側:

problem info

在ImageVie是不是

android:layout_width="match_parent" 

我應該照顧這個嗎? (不,這不是一個Eclipse故障,它也顯示在模擬器中。)

我會感謝您的幫助。我究竟做錯了什麼?

+1

你可以試一下'android:scaleType =「fitXY」 android:adjustViewBounds =「true」'? – 2014-09-27 16:17:04

+0

你可以更改比例類型android:scaleType =「fitStart」爲fitxy或centercrop .. – Shiva 2014-09-27 16:18:06

+0

你確定空白不是樣本圖像的一部分嗎?你的代碼對我來說看起來很好。另外,你有沒有嘗試過不同的'scaleType'來看看會發生什麼? – 2014-09-27 16:30:27

回答

1
Try using scale type to fit X and Y coordinates. This will solve if its not a glitch.  


<ImageView 
      android:id="@+id/imgView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scaleType="fitXY" 
      android:adjustViewBounds="true" 
      android:contentDescription="@string/testImgDescription" 
      android:src="@drawable/test_img" /> 
+0

確實如此。謝謝。但爲什麼fitStart會導致這個問題呢?圖像應該比屏幕大得多。 – User1291 2014-09-27 16:41:18

+0

我認爲形象我沒那麼大,因爲你正在使用wrap_content作爲身高。更多的完全取決於你的屏幕密度。如果你認爲圖像足夠大,嘗試使用縮放類型cropCenter,看看結果是什麼 – 2014-09-27 16:52:40