android ScrollView的用法

zmwell 2011-11-01 10:21:37
我想给activity加入滚动条,xml文件格式为
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView" android:layout_width="match_parent"
android:layout_height="wrap_content" >

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/listlinear"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<ListView
android:id="@id/android:list"
android:drawSelectorOnTop="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<TextView
android:id="@+id/neighborInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/buttonstart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/buttonstop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
可是这样的结果是内容未全屏显示,则已经出现滚动条,致使内容未全屏显示,想实现内容大于屏幕时才出现滚动条,有人知道如何解决吗?
...全文
43031 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
jsonbor 2013-09-11
  • 打赏
  • 举报
回复
感谢你,帮我大忙!
jike0804wanghuiyun 2012-10-10
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]

XML code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="fill_parent"
android:weightSum="1">
<Relative……
[/Quote]

也碰到这个问题了,多谢你啦
fmworld 2011-11-02
  • 打赏
  • 举报
回复
scrollview 是针对自己的第一次子元素的,你的这个listview是其一个子元素,给一定的空间显示,如楼上所说,你那个listview的滚动条应该是listview自身的,你在scrollview中多添加几个button,然后scrollview的滚动条就会出现了。
zmwell 2011-11-02
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 fmworld 的回复:]
XML code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="fill_parent"
android:weightSum="1">
<Relati……
[/Quote]多谢了,就要的这种效果
j_f0001 2011-11-02
  • 打赏
  • 举报
回复
ScrollView和ListView不能同时存在,好像在android中有两个可以滚动的控件同时在在或者嵌入存在的时候有LZ所说的问题出现
knxw0001 2011-11-02
  • 打赏
  • 举报
回复
android:layout_width="match_parent"
android:layout_height="wrap_content"

都改为fill_parent:

fill_parent布局指将视图(在Windows中称为控件)扩展以填充所在容器的全部空间。

wrap_content布局指根据视图内部内容自动扩展以适应其大小。
fmworld 2011-11-02
  • 打赏
  • 举报
回复
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="fill_parent"
android:weightSum="1">
<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_height="match_parent" android:layout_width="match_parent">
<ListView android:id="@id/android:list"
android:drawSelectorOnTop="false" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_above="@+id/buttonstart"/>
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/buttonstart"
android:layout_above="@+id/buttonstop"
android:layout_alignParentLeft="true"></Button>
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/buttonstop"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"></Button>
</RelativeLayout>
</LinearLayout>
zmwell 2011-11-02
  • 打赏
  • 举报
回复
这是截图,其中listView里有好多项,但未全屏显示,可以把listView占的地方弄大一些吗?
zmwell 2011-11-02
  • 打赏
  • 举报
回复
mazha111 2011-11-02
  • 打赏
  • 举报
回复
学习下
zmwell 2011-11-02
  • 打赏
  • 举报
回复
zmwell 2011-11-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 kechanghe0705 的回复:]
ScrollView和ListView不能同时存在,好像在android中有两个可以滚动的控件同时在在或者嵌入存在的时候有LZ所说的问题出现
[/Quote]有解决方法吗?
zmwell 2011-11-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 fmworld 的回复:]
scrollview 是针对自己的第一次子元素的,你的这个listview是其一个子元素,给一定的空间显示,如楼上所说,你那个listview的滚动条应该是listview自身的,你在scrollview中多添加几个button,然后scrollview的滚动条就会出现了。
[/Quote]
我想把listView里的东西全屏显示,而不是在未全屏显示时就出现滚动条,不知道有没有什么解决方法
【课程特点】1、231节大容量课程:包含了SwiftUI的大部分知识点,详细讲解SwiftUI的方方面面;2、15个超级精彩的实例:包含美食、理财、健身、教育、电子商务等各行业的App实例;3、创新的教学模式:手把手教您SwiftUI用户界面开发技术,一看就懂,一学就会;4、贴心的操作提示:让您的眼睛始终处于操作的焦点位置,不用再满屏找光标;5、语言简洁精练:瞄准问题的核心所在,减少对思维的干扰,并节省您宝贵的时间;6、视频短小精悍:即方便于您的学习和记忆,也方便日后对功能的检索;7、齐全的学习资料:提供所有课程的源码,在Xcode 11 + iOS 13环境下测试通过; 更好的应用,更少的代码!SwiftUI是苹果主推的下一代用户界面搭建技术,具有声明式语法、实时生成界面预览等特性,可以为苹果手机、苹果平板、苹果电脑、苹果电视、苹果手表五个平台搭建统一的用户界面。SwiftUI是一种创新、简单的iOS开发中的界面布局方案,可以通过Swift语言的强大功能,在所有的Apple平台上快速构建用户界面。 仅使用一组工具和API为任何Apple设备构建用户界面。SwiftUI具有易于阅读和自然编写的声明式Swift语法,可与新的Xcode设计工具无缝协作,使您的代码和设计**同步。自动支持动态类型、暗黑模式、本地化和可访问性,意味着您的**行SwiftUI代码已经是您编写过的非常强大的UI代码了。 

80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧