使Linearlayout可滚动而不使用Scrollview [英] Make Linearlayout scrollable without using Scrollview

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

问题描述

我有一个Linearlayout,我想使其不使用ScrollView即可滚动.是否有可能.任何建议将不胜感激.这是详细信息: 如果我使用ScrollView包装LinearLayout,可以,但是当我在LinearLayout中使用ListView时(因为这是我的客户要求),它说不要在ScrollView中使用ListView.我必须使用ListView显示50个产品列表,并且必须将此ListView放在LinearLayout内,同时整个布局将是可滚动的.是否有可能.这是骨骼:

I have a Linearlayout and I want to make it scrollable without using ScrollView. Is it possible. Any suggestions will be appreciated. Here's the detail: If I wrap the LinearLayout using ScrollView, it is ok but when I used a ListView inside LinearLayout(because it is my clients requirement), it said do not use ListView inside ScrollView. I have to show 50 product list using ListView and I have to put this ListView inside LinearLayout and at the same time whole layout will be scrollable. Is it possible. Here is the skeleton:

<LinearLayout>
  <RelativeLayout>
    <LinearLayout> 
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <TextView>
    </LinearLayout>
    <LinearLayout>
        <ListView>
    </LinearLayout> 
  </RelativeLayout>
</LinearLayout>

重要提示:请参阅要在其中添加50个列表项的ListView.因此,如何使整个LinearLayout可滚动.

Important: See the ListView where I want to add 50 list item. So how can I make this total LinearLayout scrollable.

推荐答案

实际上,在进行了一些研究之后,我想出了一个解决该问题的方法:

Actually after doing some research, I come up with a solution for this problem:

首先,我想以一种非常简单的方式来解释问题.

  1. LinearLayout将是可滚动的.为此,我们可以使用ScrollView,但有时我们需要在LinearLayout中使用ListView.
  2. 我们知道在ScrollView内部我们无法使用其他Listview之类的滚动视图

如何解决?

ListView本质上是可滚动的,因此我们可以在ListView中添加页眉和页脚.结论:

ListView is scrollable inherently so we can add header and footer in the ListView. As a conclusion:

  1. 创建布局header.xml,footer.xml和list.xml
  2. 在主活动中从list.xml查找ListView引用,并在ListView引用中动态添加页眉和页脚.

这篇关于使Linearlayout可滚动而不使用Scrollview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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