2012-07-26 47 views
0

我有一個很長的垂直圖像(224x1600)。我希望它適合圖像寬度,並垂直滾動。它需要可以滾動。我已經嘗試了一切並不能得到它的工作:\在Android中縮放圖像不像應該那樣工作

這裏是我有什麼

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

       <LinearLayout 
        android1:id="@+id/tab3" 
        android1:layout_width="fill_parent" 
        android1:layout_height="fill_parent" > 

        <ImageView 
         android:id="@+id/imageView1" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:src="@drawable/tiles" /> 
       </LinearLayout> 
      </ScrollView> 

第二個問題是:有沒有辦法阻止圖像縮放?圖像是224x1632,並在我的星系聯結中顯示。在Nexus 7上(屏幕大得多但DP較低)則達到了199x1440。奇怪的縮放比例爲88%。我能阻止這個嗎?我需要它在所有機器上顯示224x1632並相應地縮放寬度。

非常感謝!

回答

0

如果您需要避免完全縮放,則應將您的繪圖放置在res/drawable-nodpi文件夾中。請記住,在不同密度的設備上,物理尺寸會有很大不同,但只要您瞭解風險,那就是您應該追求的解決方案。

關於第一個問題,我傾向於認爲你需要做的代碼中的一些體力勞動,但儘管我現在還不能對其進行測試,這也可能工作:

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:src="@drawable/tiles" 
     /> 
</ScrollView> 

試試看,讓我知道它是怎麼回事。

0

它應該工作...我認爲問題是,你有android1:,它是假設是android:

喜歡的東西:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/tab3" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/tiles" /> 

    </LinearLayout> 
</ScrollView> 

至於第二個問題,你可以嘗試使用android:minWidth=""android:minHeight=""來查看是否可以解決您的問題。

編輯:嘗試android:scaleType="fitCenter"它將顯示圖像原樣。

希望有所幫助。

+0

將其更改爲android:仍然沒有。而且,每個設備的最小寬度也不同。所以這是行不通的......無論如何,在XML中 – Brian 2012-07-26 00:35:09

+0

奇怪的是,我發佈的代碼適合我。你可以發佈你的主要活動類,也許這是問題所在。或者您的圖像未正確加載。確保清理項目,然後關閉並重新打開Eclipse(如果您使用的是Eclipse)。 – 0gravity 2012-07-26 00:39:09

+0

關於另一個問題,你可以嘗試'android:scaleType =「fitCenter」'我會更新我的答案。 – 0gravity 2012-07-26 00:40:34

相關問題