Android:滚动视图问题 [英] Android: ScrollView Issue

查看:16
本文介绍了Android:滚动视图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 ScrollView 时遇到了许多问题.最近我尝试创建一个内容超过屏幕尺寸的 LinearView,所以我创建了带有父元素 ScrollView 的新布局,并将其宽度和高度设置为自定义值(布局必须显示为对话框 - 而不是填充整个屏幕).

I have had a number of problems with ScrollViews. Recently I tried to create a LinearView which content exceeds the screen size so I created the new layout with parent element ScrollView and set its width and height to custom values (the layout has to appear as dialog - not filling the whole screen).

当元素被选中时,红色边框似乎包含了预定义的 ScrollView LayoutWidth 和 LayoutHeight 的矩形,这是可以的.然后我放置在 LinearView 中并将值 LayoutWidth 和 LayoutHeight 设置为 fill_parent.

When the element is selected the red border appears to embrace the rectangle of predefined ScrollView LayoutWidth and LayoutHeight which is OK. Then I placed inside the LinearView and set the values LayoutWidth and LayoutHeight to fill_parent.

然后当我开始将元素添加到 LinearLayout 时,边框(红色 lile)包裹了插入的元素,而不是整个父 ScrollView.

Then when I started to add the elements into the LinearLayout the border (red lile) wrapped the inserted elements, not the whole parent ScrollView.

因此,当 LinearLayout(ScrollView 的子级)的内容超过父级 ScrollView 的大小时,滚动不会出现并且底部元素根本不可见.

So when the content of the LinearLayout (child of ScrollView) exceeded the size of parent ScrollView the scroll didn't appear and the bottom elements are simply invisible.

无论如何......在那种情况下,XML 内容过于广泛,无法在此处发布问题,现在我在使用更简单的示例时遇到了同样的问题.

Anyway.. in that case the XML content was too extensive to post the question here and now I'm having the same problem with the more simple example.

布局的以下部分旨在成为可滚动的 EditText(以防用户输入超过小部件的主要大小).我想将 EditText 高度设置为 120px,所以我将父 ScrollView 高度设置为 120px,将子 EditText 高度设置为 fill_parent.同样在这种情况下,EditText 不会填充整个 ScrollView 区域,而是一行:

The following part of the layout is intended to be a scrollable EditText (in case the user input exceeds the primary size of the widget). I wanted to set the EditText height to 120px, so I set the parent ScrollView height to 120px and the child EditText to fill_parent. Again in this case the EditText doesn't fill the whole ScrollView area but a single line:

 <ScrollView android:layout_height="120px" android:layout_width="fill_parent">
<EditText android:id="@+id/txtContent" android:layout_height="fill_parent" android:layout_width="fill_parent" android:text="TestContent">
</EditText>
</ScrollView>

有谁知道如何重塑上面的内容,以便 EditText 填充父控件,如果用户的输入超过控件大小,滚动出现?

Does anyone know how to reshape the content above so the EditText fills the parent control and in case the user's input exceeds the control size the scroll appears?

谢谢!

以下是布局截图

删除了无效的 ImageShack 链接
删除了无效的 ImageShack 链接

推荐答案

你的 EditText 应该有 wrap_content 的高度.fill_parentScrollView 中没有意义.如果您希望 EditText 在内容小于 ScrollView 时填充 ScrollView,请使用 android:fillViewport="true"ScrollView 上.

Your EditText should have a height of wrap_content. fill_parent has no meaning in a ScrollView. If you want the EditText to fill your ScrollView when it's content is smaller than the ScrollView, use android:fillViewport="true" on the ScrollView.

这篇关于Android:滚动视图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆