你如何使 LinearLayout 可滚动? [英] How do you make a LinearLayout scrollable?

查看:86
本文介绍了你如何使 LinearLayout 可滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在屏幕上有很多项目,我需要使用滚动条以便用户可以向下滚动.但是,滚动条要么不可见,要么不起作用.如何将滚动条添加到 LinearLayout?

解决方案

包裹线性布局

参见此处的示例:

 <?xml version="1.0" encoding="utf-8"?><线性布局android:layout_width="fill_parent"android:layout_height="fill_parent"xmlns:android="http://schemas.android.com/apk/res/android"><滚动视图android:layout_width="fill_parent"android:layout_height="wrap_content"><线性布局android:layout_width="wrap_content"android:layout_height="wrap_content"机器人:方向=垂直"><!-- 这里的内容--></LinearLayout></ScrollView></LinearLayout>

<块引用>

注意:fill_parent 在 API 级别 8 中已弃用并重命名为 ma​​tch_parent和更高.

I have lot of items on the screen and I need to use the scrollbar so the user can scroll down. However, the scroll is either not visible or it's not working. How is it possible to add a scrollbar to a LinearLayout?

解决方案

Wrap the linear layout with a <ScrollView>

See here for an example:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout 
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       xmlns:android="http://schemas.android.com/apk/res/android">
       <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <LinearLayout 
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:orientation="vertical">
                  <!-- Content here -->
            </LinearLayout>
      </ScrollView>
 </LinearLayout>

Note: fill_parent is deprecated and renamed to match_parent in API Level 8 and higher.

这篇关于你如何使 LinearLayout 可滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆