[英]ScrollView doesn't work
My Layout has a few complex layouts and they are pretty big. 我的布局有一些复杂的布局,它们很大。 That's why I need a
ScrollView
. 这就是为什么我需要
ScrollView
的原因。 But whatever I try it doesn't work. 但是,无论我尝试什么,都行不通。
Here is my layout file: 这是我的布局文件:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:fillViewport="true"
android:layout_weight="1"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.33"
android:id="@+id/Linear1"
>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@color/tileColor1"
android:layout_weight="1"
android:id="@+id/tileLayout1"
android:onClick="openFirst"
>
I have only posted a part of it but all the closing tags are ok and inside my RelativeLayout
there are 2 textViews
and an image. 我只发布了一部分,但所有的结束标记都可以,并且在我的
RelativeLayout
有2个textViews
和一个图像。 There are 9 more RelativeLayout
s with the same structure. 还有9个具有相同结构的
RelativeLayout
。
How can I fix the problem and why doesn't it work? 如何解决该问题,为什么不起作用? It doesn't even show a scrollbar.
它甚至不显示滚动条。
EDIT 编辑
I have uploaded my full layout to pastebin 我已将完整版面上传到pastebin
EDIT 2 编辑2
On the developer.android it is said: You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
在developer.android上说:
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
Mine doesn't deal with the scrolling at all. 我的根本不处理滚动。 I suppose it is this way because I edit LayoutParams in code.
我想是因为我在代码中编辑LayoutParams。 How do I fix this?
我该如何解决?
1. Try removing android:layout_weight="1"
and android:orientation="vertical"
. 1.尝试删除
android:layout_weight="1"
和android:orientation="vertical"
。
2. Ensure that there is only one ViewGroup
inside the ScrollView
(ie one child as they say). 2.确保
ScrollView
只有一个ViewGroup
(即,他们所说的一个孩子)。 I assume you've done this, but as you haven't provided your full layout I couldn't confirm it. 我认为您已经完成了此操作,但是由于您没有提供完整的布局,因此无法确认。
ScrollView only accepts one child view. ScrollView仅接受一个子视图。 So wrap everything inside it in a LinearLayout with wrap_content set as height and you're set.
因此,将其中的所有内容包装在LinearLayout中,并将wrap_content设置为height即可。
I had the same problem, and I do not know if my solution helped (mainly because it is a very late response), but my ScrollView
not worked since set up a layout that fit exactly on the screen, so it was not necessary to create scrolling. 我遇到了同样的问题,我不知道我的解决方案是否有帮助(主要是因为响应太晚了),但是我的
ScrollView
不能正常工作,因为它设置了恰好适合屏幕的布局,因此没有必要创建滚动。 When increased my layout (I put all my items with android:layout_height = WRAP_CONTENT
) became operational. 增加布局后(我将所有项目都放置在
android:layout_height = WRAP_CONTENT
)就可以使用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.