A method for implementing a pull-down refresh component based on FrameLayout on Android

Through the InspurRefreshLayout class and RefreshState enumeration type, combined with gesture listeners and refresh event listeners, it solves the problem that Android system components cannot customize the top refresh view and automatically control the display of blank pages, and achieves flexible customization and compatibility of pull-down refresh components. processing, improving development efficiency.

CN114237669BActive Publication Date: 2024-09-17山东浪潮智慧医疗科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111570266.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-21
Publication Date
2024-09-17
Estimated Expiration
2041-12-21

AI Technical Summary

Technical Problem

Existing Android system components cannot customize the top refresh view, and cannot automatically control whether to display a customized blank page, resulting in increased development complexity and redundancy, which affects the development of large-scale APPs.

Method used

Inherit FrameLayout through the InspurRefreshLayout class, maintain gesture listeners, scrollers, and refresh event listeners, define the RefreshState enumeration type to control the status of the pull-down refresh component, and uniformly set the blank View through the setEmptyView method to achieve compatible processing of different list components.

Benefits of technology

Implemented the customization of the top refresh view of the pull-down refresh component and the unified setting of the blank view, improving the compatibility and development efficiency of the component.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114237669B
    Figure CN114237669B
Patent Text Reader

Abstract

The present invention provides a method for implementing a pull-down refresh component based on FrameLayout on an Android terminal, which belongs to the field of Android system component optimization. The present invention implements a pull-down refresh operation that can flexibly customize the top refresh view, and monitors in real time whether a new View is added in the refresh component according to data to display a customized blank page. The present invention standardizes the APIs of all top refresh views, ensures that the top refresh view implementation class style implementation class is universally available, and can pass in a customized blank View view style to ensure that the view is automatically displayed when the data is empty.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of Android system component optimization, and in particular to a method for implementing a pull-down refresh component based on FrameLayout on an Android end. Background Art

[0002] With the rapid development of mobile Internet, the list styles and functions of large APPs are becoming more and more complex. The list requires users to manually refresh the data. The official refresh component cannot be used to customize the top refresh view. Currently, there is no third-party library that automatically controls whether to display a customized blank page at the refresh component level. Unified blank page control at the pull-down refresh component level can make blank page settings simple, because the current official list components on the Android side include ScrollView, NestedScrollView, ListView, and RecyclerView, etc. None of them have the function of setting blank pages, and can only be optimized by custom components, which increases complexity and redundancy, and is not conducive to the subsequent development of large-scale APPs. Summary of the invention

[0003] In order to solve the above technical problems, the present invention provides a method for implementing a pull-down refresh component based on FrameLayout on an Android side, which solves the problem that the official example cannot customize the top refresh view and automatically control whether to display a customized blank page.

[0004] The technical solution of the present invention is:

[0005] A method for implementing a pull-to-refresh component based on FrameLayout on an Android side, using the InspurRefreshLayout class to inherit FrameLayout as a base class, maintaining instances of a gesture listener InspurGestureDetector, a scroller AutoScroller, a refresh event listener InspurRefreshListener, and a top refresh view InspurOverView in this class, wherein the gesture listener and the scroller are initialized in the init method, the refresh event listener and the top refresh view need to be passed in by an external caller, and the top refresh view is controlled by selecting the timing through the control of the pull-down state.

[0006] Furthermore,

[0007] Define the InspurOverView abstract class to inherit FrameLayout. In this class, first define the enumeration type RefreshState, which contains:

[0008] Initial state: STATE_INIT

[0009] Header display status: STATE_VISIBLE

[0010] State beyond the refreshable distance: STATE_OVER

[0011] Refreshing state: STATE_REFRESH

[0012] The state after the hand is released beyond the refresh position: STATE_OVER_RELEASE.

[0013] In the InspurRefreshLayout class, these states are used to determine which step the sliding operation has reached, and the gesture listener InspurGestureDetector listens to the sliding. The initial state of the pull-down refresh component is the initial state. If the sliding distance exceeds the set minimum distance, the component state becomes a displayable state. If you continue to slide down and exceed the refreshable distance, the state becomes a refreshable state. Once you let go of this state, the state becomes the state after you let go of the refresh position. The list returns to the header height. After the recovery is complete, the component becomes a refreshing state. At this time, InspurRefreshLayout will call the refresh() method and automatically execute the onRefresh() method of OverView and mRefreshListner to ensure that the refresh component calls the relevant interface. After executing the interface-related logic, call back the onRefreshFinished() method of InspurRefreshLayout to restore the initial state and complete this refresh operation.

[0014] Furthermore,

[0015] First, InspurRefreshLayout has a setEmptyView() method, which passes the unified customized view into the component. The mEmptyView variable in the component records this View.

[0016] Then, during the initialization process, InspurRefreshLayout will judge the list View of the package, determine the current type, and perform different compatibility processing according to the type.

[0017] Going further,

[0018] ScrollView: Get the number of sub-Views in scrollView. If it is a single node, use recursive method to traverse and find the number of sub-Views at the lowest level. If the number of sub-Views is 0, it means that the list loaded by ScrollView is empty. Then set the saved mEmptyView to set the blank custom View to the lowest level View by setting the addView() method to display the blank View.

[0019] NestedScrollView: Get the number of sub-Views in NestedScrollView. If it is a single node, use a recursive method to traverse and find the number of sub-Views at the lowest level. If the number of sub-Views is 0, then call the isNestedScrollingEnabled() method of the class. If this method is false at the same time, it means that the list loaded by ScrollView is empty. Then set the saved mEmptyView to the lowest level View by setting the addView() method, and directly set the width and height of the child elements of NestedScrollView to -1, indicating that the entire screen is filled, so as to display a blank View.

[0020] ListView: Get the number of additional Views added according to the getHeaderViewsCount() and getFooterViewsCount() methods, and then get the number of Views cached in the mRecycler variable. Add the three together. If the result is zero, it means the list is empty. Then you can use addHeaderView to add mEmptyView to ListView to display a blank View.

[0021] RecyclerView: First, get the adapter Adapter according to getAdapter(), and then get the value of getItemCounts(). This value needs to be checked for positive value, and then subtract the number of Views whose getItemViewType() value is -1. If the result is zero, it means that the component is an empty list. Then execute the method of creating an empty ViewHolder for the Adapter adapter, and then bind the ViewHolder to mEmptyView to display a blank View.

[0022] When the list data is no longer empty, the previously added blank view needs to be cleaned up through the reverse steps. This process cannot affect the value of mEmptyView.

[0023] The beneficial effects of the present invention are

[0024] The pull-down refresh component can be used to customize the top refresh view, and the blank View method can be uniformly set to improve component compatibility. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] Figure 1 It is a working schematic diagram of the present invention. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0027] The present invention provides a method for realizing a pull-down refresh component based on FrameLayout on an Android terminal, which can flexibly customize the top refresh view by realizing the pull-down refresh operation, and monitor in real time whether a new View is added in the refresh component according to the data to display a customized blank page.

[0028] 1. Basic structure of pull-down refresh component

[0029] First, the present invention uses the InspurRefreshLayout class to inherit FrameLayout as the base class, and maintains instances of the gesture listener InspurGestureDetector, the scroller AutoScroller, the refresh event listener InspurRefreshListener and the top refresh view InspurOverView in this class, wherein the gesture listener and the scroller are initialized in the init method, the refresh event listener and the top refresh view need to be passed in by the external caller, and the top refresh view is controlled by selecting the appropriate time through the control of the pull-down state.

[0030] InspurOverView is an abstract class. Different top refresh views need to implement this class and customize the View as needed. When using the pull-down refresh component, select the appropriate class and pass in the instance to customize the top refresh view.

[0031] This method utilizes a plug-in design, which not only achieves decoupling but also achieves reuse of the same style.

[0032] 2. Flexible configuration to refresh header style

[0033] Define the InspurOverView abstract class to inherit FrameLayout. In this class, first define the enumeration type RefreshState, which contains:

[0034] Initial state: STATE_INIT

[0035] Header display status: STATE_VISIBLE

[0036] State beyond the refreshable distance: STATE_OVER

[0037] Refreshing state: STATE_REFRESH

[0038] The state after releasing the hand beyond the refresh position: STATE_OVER_RELEASE

[0039] In the InspurRefreshLayout class, these states are used to determine which step the sliding operation has reached, and the gesture listener InspurGestureDetector listens to the sliding. The initial state of the pull-down refresh component is the initial state. If the sliding distance exceeds the set minimum distance, the component state becomes a displayable state. If you continue to slide down and exceed the refreshable distance, the state becomes a refreshable state. Once you let go of this state, the state becomes the state after you let go of the refresh position. The list returns to the header height. After the recovery is complete, the component becomes a refreshing state. At this time, InspurRefreshLayout will call the refresh() method and automatically execute the onRefresh() method of OverView and mRefreshListner to ensure that the refresh component calls the relevant interface. After executing the interface-related logic, call back the onRefreshFinished() method of InspurRefreshLayout to restore the initial state and complete this refresh operation.

[0040] 3. Solve the blank page display problem of compatible various list components

[0041] There are four list components in the Android system, namely ScrollView, NestedScrollView, ListView and RecyclerView. These four components do not have a fixed API to display blank page styles, and they must be customized to achieve this function. Refresh components are often used with these four components and their custom components to achieve simple operations in a unified API operation. Refresh components implement compatibility processing.

[0042] First, InspurRefreshLayout has a setEmptyView() method, which passes the unified customized view into the component. The mEmptyView variable in the component records this View.

[0043] Then, during the initialization process, InspurRefreshLayout will judge the list View of the package. It determines the current type and performs different compatibility processing according to the type:

[0044] (1)ScrollView: Get the number of sub-Views in the scrollView. If it is a single node, use a recursive method to traverse and find the number of sub-Views at the lowest level. If the number of sub-Views is 0, it means that the list loaded by the ScrollView is empty. Then, use the addView() method to set the saved mEmptyView to the lowest level View to display the blank View.

[0045] (2) NestedScrollView: Get the number of sub-Views in the NestedScrollView. If it is a single node, use a recursive method to traverse and find the number of sub-Views at the lowest level. If the number of sub-Views is 0, then call the isNestedScrollingEnabled() method of the class. If this method is false at the same time, it means that the list loaded by ScrollView is empty. Then, set the saved mEmptyView to the lowest level View by setting the addView() method, and directly set the width and height of the child elements of NestedScrollView to -1, indicating that the entire screen is filled, so as to display a blank View.

[0046] (3) ListView: Get the number of additional Views added according to the getHeaderViewsCount() and getFooterViewsCount() methods, and then get the number of Views cached in the mRecycler variable. Add the three together. If the result is zero, it means the list is empty. Then use addHeaderView to add mEmptyView to ListView to display a blank View.

[0047] (4) RecyclerView: First, get the adapter Adapter according to getAdapter(), and then get the value of getItemCounts(). This value needs to be checked for positive value, and then subtract the number of Views whose getItemViewType() value is -1. If the result is zero, it means that the component is an empty list. Then execute the method to create an empty ViewHolder for the Adapter adapter, and then bind the ViewHolder to mEmptyView to display the blank View.

[0048] Note: When the list data is no longer empty, the previously added blank view should be cleared through the reverse steps. This process cannot affect the value of mEmptyView.

[0049] The present invention provides a specified InspurOverView class. When using the pull-down refresh component, the pull-down refresh component can be flexibly customized by passing in an instance of the InspurOverView class. The blank View is uniformly set to be compatible with various list components.

[0050] The above description is only a preferred embodiment of the present invention, which is only used to illustrate the technical solution of the present invention, and is not used to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A method for implementing a pull-down refresh component based on FrameLayout on an Android terminal, characterized in that: Use the InspurRefreshLayout class to inherit FrameLayout as the base class. In this class, maintain instances of the gesture listener InspurGestureDetector, the scroller AutoScroller, the refresh event listener InspurRefreshListener, and the top refresh view InspurOverView. The gesture listener and the scroller are initialized in the init method. The refresh event listener and the top refresh view need to be passed in by the external caller, and the top refresh view is controlled by selecting the timing through the pull-down state control. Define the InspurOverView abstract class to inherit FrameLayout. In this class, first define the enumeration type RefreshState, which contains: Initial state: STATE_INIT Header display status: STATE_VISIBLE State beyond the refreshable distance: STATE_OVER Refreshing state: STATE_REFRESH The state after the hand is released beyond the refresh position: STATE_OVER_RELEASE.

2. The method according to claim 1, characterized in that In the InspurRefreshLayout class, these states are used to determine which step the sliding operation has reached, and the gesture listener InspurGestureDetector listens to the sliding. The initial state of the pull-down refresh component is the initial state. If the sliding distance exceeds the set minimum distance, the component state becomes a displayable state. If you continue to slide down and exceed the refreshable distance, the state becomes a refreshable state. Once you let go of this state, the state becomes the state after you let go of the refresh position. The list returns to the header height. After the recovery is complete, the component becomes a refreshing state. At this time, InspurRefreshLayout will call the refresh() method and automatically execute the onRefresh() method of OverView and mRefreshListner to ensure that the refresh component calls the relevant interface. After executing the interface-related logic, call back the onRefreshFinished() method of InspurRefreshLayout to restore the initial state and complete this refresh operation.

3. The method according to claim 1, characterized in that: First, InspurRefreshLayout has a setEmptyView() method, which passes the unified customized view into the component. The mEmptyView variable in the component records this View. Then, during the initialization process, InspurRefreshLayout will judge the list View of the package, determine the current type, and perform different compatibility processing according to the type.

4. The method according to claim 3, characterized in that ScrollView: Get the number of sub-Views in scrollView. If it is a single node, use recursive method to traverse and find the number of sub-Views at the lowest level. If the number of sub-Views is 0, it means that the list loaded by ScrollView is empty. Then set the saved mEmptyView to set the blank custom View to the lowest level View by setting the addView() method to display the blank View.

5. The method according to claim 3, characterized in that: NestedScrollView: Get the number of sub-Views in NestedScrollView. If it is a single node, use a recursive method to traverse and find the number of sub-Views at the lowest level. If the number of sub-Views is 0, then call the isNestedScrollingEnabled() method of the class. If this method is false at the same time, it means that the list loaded by ScrollView is empty. Then set the saved mEmptyView to the lowest level View by setting the addView() method, and directly set the width and height of the child elements of NestedScrollView to -1, indicating that the entire screen is filled, so as to display a blank View.

6. The method according to claim 3, characterized in that ListView: Get the number of additional Views added according to the getHeaderViewsCount() and getFooterViewsCount() methods, and then get the number of Views cached in the mRecycler variable. Add the three together. If the result is zero, it means the list is empty. Then use addHeaderView to add mEmptyView to ListView to display a blank View.

7. The method according to claim 3, characterized in that RecyclerView: First, get the adapter according to getAdapter(), then get the value of getItemCounts(), which needs to be checked for positive value, and then subtract the number of Views with a getItemViewType() value of -1. If the result is zero, it means that the component is an empty list, and then execute the method of creating an empty ViewHolder for the Adapter adapter, and then bind the ViewHolder to mEmptyView to display a blank View.

8. The method according to claim 3, characterized in that When the list data is no longer empty, the previously added blank view should be cleaned up through the reverse steps. This process should not affect the value of mEmptyView.