<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 Project并编辑了上面的main.xml。然后我定制视图来绘制图像。为了查看滚动自定义视图的效果,我如上所述设置了宽度和高度。现在,我可以在自定义视图中看到图像,但它不能滚动。你能告诉我问题出在哪里吗?我应该添加更多的东西吗?
发布于 2011-07-22 02:48:18
在ScrollView和它的内容之间存在着相互作用。例如,如果您将以下TextView插入到ScrollView中,而不是NwcDrawingArea小部件:
<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,它的文本比屏幕长,并且ScrollView显示滚动条,使您可以看到TextView 的隐藏部分,达到文本的范围。现在,更改TextView layout_width="2000dp“。TextView变成一个全屏绿色区域,其中只有一行文本位于屏幕的右侧。当然,ScrollView不显示水平滚动条。但是,即使我们将TextView调整为比屏幕长得多,ScrollView也没有显示垂直滚动条。ScrollView正在尝试确定其内容中视觉上有趣的部分,因此您需要了解您正在子类化的小部件的行为。
例如,ScrollView尊重LinearLayout和RelativeLayout的布局大小,这与您期望它在TextView中的行为方式相同。实际上,将LinearLayout或RelativeLayout --而不是像TextView这样的视图--作为ScrollView的子级是很常见的。将您的TextView放在固定高度的LinearLayout中,您应该会获得预期的行为。
https://stackoverflow.com/questions/6780270
复制相似问题