安卓开发:滚动面板的使用

本文介绍了如何在安卓开发中利用ScrollView组件创建滚动面板,通过简单的操作,实现手机屏幕上信息的无限滚动,帮助开发者在有限的屏幕空间内展示更多内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

手机屏幕是有限的,为了让有限的屏幕输出更多的信息,只需要用手指往上一滑就行了,那这滚动面板是如何做出来的呢?

其实是用了ScrollView,

方法如下

<ScrollView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >
                <!-- 然后在这里放置其他布局 -->
                <!--  例如我们放十个TextView -->
                <!-- ScrollView只允许放一个控件 所以我们用LInearLayout把他们收起来 -->
              <LinearLayout
            android:id="@+id/LinearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >             
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                    android:textSize="50dp"
                     android:text="第一行 "
                    />
    <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                      android:textSize="50dp" 
                     android:text="第二行 "
                    />
<TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                      android:textSize="50dp"
                     android:text="第三行 "
                    />
<TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                      android:textSize="50dp"
                     android:text="第四行 "
                    />
<TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                      android:textSize="50dp"
                     android:text="第五行 "
                    />
<TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                      android:textSize="50dp" 
                     android:text="第六行 "
                    />
<TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                      android:textSize="50dp"
                     android:text="第七行 "
                    />
<TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                      android:textSize="50dp"
                     android:text="第八行 "
                    />
<TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                      android:textSize="50dp"
                     android:text="第九行 "
                    />
<TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                      android:textSize="50dp"
                     android:text="第十行 "
                    />
            </LinearLayout>

</ScrollView>

展示一下运行效果吧(发现模拟器屏幕太长又加了几行,注意边边是有滚动条的)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值