SoFunction
Updated on 2025-03-08

Solution to nest ScrollView in the item of Android ListView

Solution to nest ScrollView in the item of Android ListView

Updated: October 28, 2016 16:05:32 Author: You Xingxing
Sometimes, the item of the listview needs to display more fields. Considering the display problem, the item has to nest ScrollView outside the item to implement it. How to solve this problem? Below, the editor will share with you the solution to nesting ScrollView in the item of Android ListView. Interested friends can take a look

Frontier: Sometimes, the listview item needs to display more fields. Considering the display problem, the item has to nest ScrollView to implement it. So the problem comes. When the listview needs to do click events, due to the nested use of ScrollView, the listvew click event is intercepted: I have to rewrite the listview to implement it.

/**
 *
 * @author Author: Yi Huangxing
 *
 * @daOctober 24, 2016 Time:
 *
 * @toTODO Class Description: Solution to solve the problem of nested ScrollView in ListView and ScrollView intercepting ListView's Item click event
 *
 *
 * Nesting a ScrollView in the listview, and it is normal to slide horizontally and vertically, but the Item of the Listview cannot be clicked.  After querying the Android distribution mechanism, solve it, inherit Listview and rewrite Listview's onInterceptTouchEvent.
 *
 * OnTouchEvent in onInterceptTouchEvent always calls listview to ensure that all events in listview are executed.
 * (ev) Do not intercept the slip that needs to be passed to the ScrollView.
 */
public class MyListView extends ListView {
private int flag = 0;
private float StartX;
private float StartY;
public MyListView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// Always call the touch event processing of listviewonTouchEvent(ev);
if (() == MotionEvent.ACTION_DOWN) {
StartX = ();
StartY = ();
return false;
}
if (() == MotionEvent.ACTION_MOVE) {
float ScollX = () - StartX;
float ScollY = () - StartY;
// Determine whether it is horizontal or vertical. If it is vertical, intercept the move event and up event (not intercepting will cause the listview and scrollview to perform sliding at the same time)if ((ScollX) < (ScollY)) {
flag = 1;
return true;
}
return false;
}
if (() == MotionEvent.ACTION_UP) {
if (flag == 1) {
return true;
}
return false;
}
return (ev);
}
}

The above is the solution to nesting ScrollView in the item of Android ListView introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!

  • scrollow
  • listview

Related Articles

  • Detailed explanation of attribute animation for Android source code analysis

    It is quite cool to realize animation effects on mobile phones. Since the Android 3.0 version, the system has provided us with a brand new animation mode, property animation. Its functions are very powerful, making up for some of the shortcomings of previous tween animations and can almost completely replace tween animations. This article introduces the attribute animation in Android in detail.
    2017-02-02
  • Implement radar effects based on Android custom controls

    This article mainly introduces the implementation of radar effects based on Android custom controls, which has certain reference value. Interested friends can refer to it.
    2017-07-07
  • Android implements image switcher

    This article mainly introduces the Android image switcher in detail. The sample code in the article is introduced in detail and has a certain reference value. Interested friends can refer to it.
    2020-10-10
  • Android issue about closing orders when implementing timed tasks

    In e-commerce, payment and other fields, there are often such scenarios. If the user gives up payment after placing an order, the order will be closed after the specified time period. If you are careful, you will definitely find that there are logic like Taobao and Dong, and the time is very accurate, with an error within 1s; how did they achieve it? Today, I learned the timed tasks to achieve the problem of closing orders
    2022-05-05
  • Android frosted glass background effect simple implementation code

    This article mainly introduces the simple implementation code for Android frosted glass background effect. Friends who need it can refer to it
    2017-08-08
  • Android development: Use ExifInterface to obtain the image attributes after taking pictures

    This article mainly introduces the use of ExifInterface to obtain the image attributes after taking photos in Android development. It analyzes the specific usage techniques of ExifInterface class to operate pictures in a more detailed manner. Friends who need it can refer to it.
    2016-01-01
  • Android implements mask pop-up effect

    This article mainly introduces the effect of Android mask pop-up frames in detail. The sample code in the article is introduced in detail and has certain reference value. Interested friends can refer to it.
    2017-05-05
  • Android get high-definition app icon code sharing

    This article mainly shares the Android high-definition app icon code, which has certain reference value. Interested friends can refer to it.
    2016-09-09
  • Detailed explanation of the principle of Android's Handler mechanism

    Android's Handler mechanism is a mechanism used to process and schedule message passing between threads. It is usually used to execute tasks in background threads and return the results to the main thread to update the UI. The core of the Handler mechanism is Message and MessageQueue, as well as Looper. This article explains the principles of Android's Handler mechanism in detail. Friends who need it can refer to it.
    2023-10-10
  • Layout usage of nested RelativeLayout in LinearLayout for Android applications

    This article mainly introduces the layout usage of nested RelativeLayout in LinearLayout for Android applications. The article also provides debugging experience in some component locations in linear layout. Friends who need it can refer to it.
    2016-04-04

Latest Comments