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