Android基础(三) ScrollView

    技术2025-08-15  5

    一、瞎聊

        Activity包含了Views和ViewGroups,ViewGroups里面又可以包含Views和ViewGroups。    Views一般指的是按钮、编辑框、标签等。    ViewGroups指的是LinearLayout、AbsoluteLayout、TableLayout、RelativeLayout、FrameLayout、ScrollView。

        

    二、ScrollView

        当内容过大屏幕无法显示完全时,可以使用ScrollView来扩大器显示区域。

    【使用限制】    1.ScrollView是Framelayout的一种特殊形态。ScrollView只能包含一个View或一个ViewGroup。并且其布局必须是LinearLayout.

        2.不能将ScrollView和ListView混在一起用,因为Android本身已针对ListView作了适应大规模数据的显示处理。

    【效果图】

    【代码要点】main.xml布局文件里本身是一个scrollView。<?xml version="1.0" encoding="utf-8"?> <ScrollView android:id="@+id/widget54" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <LinearLayout android:layout_width="310px" android:layout_height="wrap_content" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button 1" /> <Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button 2" /> <Button android:id="@+id/button3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button 3" /> <EditText android:id="@+id/txt" android:layout_width="fill_parent" android:layout_height="300px" /> <Button android:id="@+id/button4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button 4" /> <Button android:id="@+id/button5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Button 5" /> </LinearLayout> </ScrollView>  

    最新回复(0)