Android:太多东西显示不完?用ScrollView吧

在开发过程中,在手机那么小的一个屏幕显示的东西有时候会大大多于你的想象。那么那么多东西我们怎么都放在手机的小屏幕上呢?


我们都知道网页上的内容我们可以滚动查看,纵向的内容我们可以往下拉查看更多的内容。横向的内容可以左右拉。那么在android程序上是否有类似的功能呢?当然有啦——————ScrollView不过ScrollView只能纵向滑动,不过已经足够了。


可能有些人会想,既然要显示很多内容,为什么不用ListView?ListView也可以显示大量的内容啊。~~ListView只能显示每一项都相同的内容,假如我第一项显示按钮,第二项显示TextView,第三项显示CheckBox呢?这样ListView就办不到了吧~还有一个就是ScrollView用起来简单多了~这才是最重要的~~当然ListView与ScrollView是互相不能替代的,都有自己的特点。下面我们来看ScrollView的用法吧。



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:imagecontrol="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

   
    <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        >
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >
    <LinearLayout
        android:id="@+id/topLayout"
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:gravity="center" >

        <LinearLayout
            android:id="@+id/user"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >


            <TextView
                android:id="@+id/userName"
                android:layout_width="wrap_content"
                android:layout_height="25dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="@dimen/distance4"
                android:background="@drawable/name_bg"
                android:gravity="center"
                android:padding="0dp"
                android:text="登录"
                android:textColor="@color/white" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="@dimen/distance4" >

        <LinearLayout
            android:id="@+id/my_order"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/myorder"
                android:textSize="@dimen/select_pic_finish_text" >
            </TextView>

            <TextView
                android:id="@+id/myorderNum"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/distance6"
                android:text="(0)"
                android:textSize="@dimen/select_pic_finish_text" >
            </TextView>
           
        </LinearLayout>
        
     <View
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="@color/divider" />
        <LinearLayout
          
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

         
            <TextView
                android:id="@+id/activityNum"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/distance6"
                android:text="(0)"
                android:textSize="@dimen/select_pic_finish_text" />
        </LinearLayout>

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="@color/divider" />

        <LinearLayout
            android:id="@+id/my_collect"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

            <ImageView
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginBottom="@dimen/distance8"
                android:layout_marginLeft="@dimen/distance10"
                android:layout_marginRight="@dimen/distance12"
                android:layout_marginTop="@dimen/distance8"
                android:scaleType="fitCenter"
                android:src="@drawable/my_collect_icon" />

        </LinearLayout>

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="@color/divider" />

        <LinearLayout
            android:id="@+id/my_review"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

            <ImageView
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginBottom="@dimen/distance8"
                android:layout_marginLeft="@dimen/distance10"
                android:layout_marginRight="@dimen/distance12"
                android:layout_marginTop="@dimen/distance8"
                android:scaleType="fitCenter"
                android:src="@drawable/my_comment_icon" />

         
        </LinearLayout>

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="@color/divider" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/systemNum"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/distance6"
                android:text="(0)"
                android:textSize="@dimen/select_pic_finish_text" />
        </LinearLayout>

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="@color/divider" />
    </LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>

可以看到,在要显示的内容外面包含了一个ScrollView就可以了~~简直就是简单粗暴。上面代码只是为了演示ScrollView的用法,ScrollView内部的代码是否有错我也没检查过~~~没办法~~就是懒。

好吧,最后再偷一下懒~效果图也不上了~~自己脑补吧~~再见

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值