2011-07-21 37 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