ScrollView和HorizontalScrollView控件

这2个是滚动条控件,ScrollView是垂直的滚动条,HorizontalScrollView是横向的滚动条。这2个控件可以相互嵌套,这样就可以横向竖向滚动。

他们都只能有一个直接的子元素。

通过一个例子就可以了解这个效果。

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
                
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"
                    android:textSize="90sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"
                    android:textSize="90sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"
                    android:textSize="90sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"
                    android:textSize="90sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"
                    android:textSize="90sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"
                    android:textSize="90sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"
                    android:textSize="90sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="hello"
                    android:textSize="90sp"/>

            </LinearLayout>
        </ScrollView>
    </HorizontalScrollView>
</LinearLayout>

这里有多个TextView,并且都是竖直放置,手机屏幕是很难放的下这么多,所以可以向下滑动显示。 如果一个TextView中内容很长,如果没有HorizontalScrollView,那么内容会换行,但是使用这个控件后,内容不会换行,可以滚动横向滚动条进行查看。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值