2011-07-21 35 views
0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:orientation="vertical"> 

    <ScrollView android:id="@+id/scroll" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:fillViewport="true"> 

     <adam.music.testfont.NwcDrawingArea android:id="@+id/NwcDrawingArea" 
       android:layout_height="2000dp" 
       android:layout_width="2000dp" 
      /> 
      </ScrollView> 
    </LinearLayout> 

我創建了Android項目並編輯瞭如上的main.xml。 然後我自定義視圖來繪製圖像。 要查看滾動自定義視圖的效果,請按照上述設置寬度和高度。 現在我可以在自定義視圖中看到圖像,但不會滾動。 你能幫我解決問題嗎? 我應該添加更多東西嗎?我無法滾動我的自定義視圖

回答

0

ScrollView及其內容之間存在相互影響。例如,如果代替你NwcDrawingArea小部件,您插入這個TextView的到您的滾動型:

<TextView android:text="8This is a lot of text 7This is a lot of text 6This is a lot of text 5This is a lot of text 4This is a lot of text 3This is a lot of text 2This is a lot of text 1This is a lot of text" 
android:layout_width="10dp" 
android:layout_height="2000dp" 
android:background="#FF00FF00" 
/> 

你會看到一個瘦小的綠色垂直的TextView其文字比屏幕長,而滾動型顯示,讓滾動條您將看到TextView 的隱藏部分在文本的範圍內。現在,更改TextView layout_width =「2000dp」。 TextView成爲一個全屏幕的綠色區域,其中有一行文本在屏幕的右側運行。當然,ScrollView不顯示水平滾動條。但是,ScrollView也不會顯示垂直滾動條,即使我們將TextView的大小設置爲比屏幕長很多。 ScrollView試圖確定其內容的視覺上有趣的部分,所以你需要了解你的子類的任何部件的行爲。

例如,ScrollView尊重LinearLayout和RelativeLayout的佈局大小,其方式與您期望的TextView行爲方式相同。實際上,製作LinearLayout或RelativeLayout是常見的,而不是像TextView這樣的視圖 - 它是ScrollView的子類。將TextView放在一個固定高度的LinearLayout中,您應該獲得您期望的行爲。

+0

@Adam你試過這個嗎? – cdhabecker