我想给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>
可是这样的结果是内容未全屏显示,则已经出现滚动条,致使内容未全屏显示,想实现内容大于屏幕时才出现滚动条,有人知道如何解决吗?
<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_height="wrap_content" 都改为fill_parent:fill_parent布局指将视图(在Windows中称为控件)扩展以填充所在容器的全部空间。wrap_content布局指根据视图内部内容自动扩展以适应其大小。
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>