Android自定义ListView示例,以创建不可滚动的ListView

In this tutorial we’ll override the ListView class to suit it according to our requirements in the android application.

在本教程中,我们将根据Android应用程序中的要求覆盖ListView类以使其适合您。

Android非滚动ListView要求 (Android Non Scrollable ListView Requirement)

A ListView comes up with its own default scrolling methods. Now if we wish to create a layout which contains a ListView along with some other views inside a parent ScrollView then you’ll notice that the scrolling gestures of the ListView don’t work as desired.

ListView带有其自己的默认滚动方法。 现在,如果我们希望创建一个包含ListView以及父ScrollView内其他视图的布局,那么您会注意到ListView的滚动手势无法正常工作。

The reason for this is that scrolling gestures received by the layout, they are all handled by the parent layout only. One workaround is to add the other views as the headers and footers of the ListView and avoid using ListView and ScrollView. But a more robust option is to create custom ListView class to suit it to our needs by making it non scrollable.

这样做的原因是,布局接收到的滚动手势都仅由父布局处理。 一种解决方法是将其他视图添加为ListView的页眉和页脚,并避免使用ListView和ScrollView。 但是,更可靠的选择是创建自定义ListView类 ,使其成为不可滚动的,从而使其满足我们的需求。

In this tutorial we’ll develop a custom ListView class and use it in a ScrollView with other child views. We’ll use Butterknife to bind the views.

在本教程中,我们将开发一个自定义ListView类,并将其在ScrollView中与其他子视图一起使用。 我们将使用Butterknife绑定视图。

项目结构 (Project Structure)

The project consists of a MainActivity and a subclass of ListView named NonScrollListView.

该项目包含一个MainActivity和一个名为NonScrollListView的ListView子类。

(Code)

The NonScrollListView class is given below:

下面给出了NonS

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值