当前位置: 代码迷 >> Android >> android ScrollView的用法,该如何处理
  详细解决方案

android ScrollView的用法,该如何处理

热度:63   发布时间:2016-05-01 13:25:30.0
android ScrollView的用法
我想给activity加入滚动条,xml文件格式为
[code=XML][/code]<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所说的问题出现
------解决方案--------------------
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">    <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>
  相关解决方案