<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>
I created Android Project and edited main.xml as above. And then I customized view to draw image. To see the effect of scrolling customized view I set width and height as above. Now I can see the image in a customized view but it doesn't scroll. Could you help me what the problem is? Should I add something more?
我创建了Android Project并编辑了main.xml,如上所述。然后我自定义视图来绘制图像。要查看滚动自定义视图的效果,请按照上面的设置宽度和高度。现在我可以在自定义视图中看到图像,但它不会滚动。你能帮帮我解决问题吗?我应该添加更多东西吗?
1 个解决方案
#1
0
There's an interplay between ScrollView and its contents. For example, if, instead of your NwcDrawingArea widget, you inserted this TextView into your ScrollView:
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"
/>
You'll see a skinny green vertical TextView whose text is longer than the screen, and the ScrollView shows scrollbars that let you see the hidden part of the TextView to the extent of the text. Now, change the TextView layout_width="2000dp". The TextView becomes a full-screen green area that has a single line of text that runs off the right side of the screen. ScrollView, of course, shows no horizontal scroll bars. However, ScrollView shows no vertical scroll bars either, even though we sized the TextView to be much longer than the screen. ScrollView is attempting to determine the visually interesting portion of its contents, so you need to understand the behavior for whatever widget you are subclassing.
您将看到一个瘦的绿色垂直TextView,其文本比屏幕长,ScrollView显示滚动条,让您可以看到TextView的隐藏部分到文本的范围。现在,更改TextView layout_width =“2000dp”。 TextView成为一个全屏绿色区域,其中有一行文本在屏幕右侧运行。当然,ScrollView没有显示水平滚动条。但是,ScrollView也没有显示垂直滚动条,即使我们将TextView的大小设置为比屏幕长得多。 ScrollView正在尝试确定其内容的视觉上有趣的部分,因此您需要了解您正在子类化的任何窗口小部件的行为。
For example, ScrollView respects the layout sizes of LinearLayout and RelativeLayout in the way that you expected it to behave with TextView. In fact, it is common to make a LinearLayout or RelativeLayout -- rather than a view such as TextView -- the child of a ScrollView. Drop your TextView in a fixed-height LinearLayout and you should get the behavior that you expected.
例如,ScrollView以您期望它使用TextView表现的方式尊重LinearLayout和RelativeLayout的布局大小。实际上,创建LinearLayout或RelativeLayout是常见的 - 而不是像TextView这样的视图 - ScrollView的子代。将TextView放在固定高度的LinearLayout中,您应该得到您期望的行为。
#1
0
There's an interplay between ScrollView and its contents. For example, if, instead of your NwcDrawingArea widget, you inserted this TextView into your ScrollView:
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"
/>
You'll see a skinny green vertical TextView whose text is longer than the screen, and the ScrollView shows scrollbars that let you see the hidden part of the TextView to the extent of the text. Now, change the TextView layout_width="2000dp". The TextView becomes a full-screen green area that has a single line of text that runs off the right side of the screen. ScrollView, of course, shows no horizontal scroll bars. However, ScrollView shows no vertical scroll bars either, even though we sized the TextView to be much longer than the screen. ScrollView is attempting to determine the visually interesting portion of its contents, so you need to understand the behavior for whatever widget you are subclassing.
您将看到一个瘦的绿色垂直TextView,其文本比屏幕长,ScrollView显示滚动条,让您可以看到TextView的隐藏部分到文本的范围。现在,更改TextView layout_width =“2000dp”。 TextView成为一个全屏绿色区域,其中有一行文本在屏幕右侧运行。当然,ScrollView没有显示水平滚动条。但是,ScrollView也没有显示垂直滚动条,即使我们将TextView的大小设置为比屏幕长得多。 ScrollView正在尝试确定其内容的视觉上有趣的部分,因此您需要了解您正在子类化的任何窗口小部件的行为。
For example, ScrollView respects the layout sizes of LinearLayout and RelativeLayout in the way that you expected it to behave with TextView. In fact, it is common to make a LinearLayout or RelativeLayout -- rather than a view such as TextView -- the child of a ScrollView. Drop your TextView in a fixed-height LinearLayout and you should get the behavior that you expected.
例如,ScrollView以您期望它使用TextView表现的方式尊重LinearLayout和RelativeLayout的布局大小。实际上,创建LinearLayout或RelativeLayout是常见的 - 而不是像TextView这样的视图 - ScrollView的子代。将TextView放在固定高度的LinearLayout中,您应该得到您期望的行为。