读书人

android ScrollView的用法,该如何解决

发布时间: 2013-09-12 22:07:04 作者: rapoo

android ScrollView的用法
我想给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>
可是这样的结果是内容未全屏显示,则已经出现滚动条,致使内容未全屏显示,想实现内容大于屏幕时才出现滚动条,有人知道如何解决吗?


[解决办法]
android:layout_width="match_parent"
android:layout_height="wrap_content"

都改为fill_parent:

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

wrap_content布局指根据视图内部内容自动扩展以适应其大小。
[解决办法]
ScrollView和ListView不能同时存在,好像在android中有两个可以滚动的控件同时在在或者嵌入存在的时候有LZ所说的问题出现
[解决办法]

<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>

读书人网 >Android

热点推荐