android listview横向滑动,Android 完美的水平方向滑动ListView

本文介绍了一个在Android开发中实现的水平ListView,适用于需要横向滑动的场景。该控件基于AdapterView,提供了类似ListView的功能,包括设置数据和Adapter。还介绍了HorizontalVariableListView,一个实现了HorizontalListView接口的具体类,包含了多种回调接口用于事件处理。示例代码展示了如何在活动中使用此控件,使用方式与ListView类似。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在Android开发 中,经常会要用到水平水平ListView(HorizontalListView),但是,Android 官方并没有提供这样一个控件, 所以在这里我给大家分享一下我在项目中用到的一个水平水平ListView,非常好用, 使用过程 中与 ListView 是一样的, 实例化组件, 设置数据,设置Adaper.

package com.example.horizontallistview.hl.widget;

import android.content.Context;

import android.util.AttributeSet;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ListAdapter;

public abstract class HorizontalListView extends AdapterView {

public HorizontalListView(Context context) {

super(context);

}

public HorizontalListView(Context context, AttributeSet attrs) {

super(context, attrs);

}

public HorizontalListView(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

}

public abstract int getScreenPositionForView(View view);

/**

* Interface definition for a callback to be invoked when an item in this

* view has been clicked and held.

*/

public interface OnItemDragListener {

/**

* Callback method to be invoked when an item in this view has been

* dragged outside the vertical tolerance area.

*

* Implementers can call getItemAtPosition(position) if they need to

* access the data associated with the selected item.

*

* @param parent

*            The AbsListView where the click happened

* @param view

*            The view within the AbsListView that was clicked

* @param position

*            The position of the view in the list

* @param id

*            The row id of the item that was clicked

*

* @return true if the callback consumed the long click, false otherwise

*/

boolean onItemStartDrag(AdapterView> parent, View view, int position,

long id);

}

public interface OnLayoutChangeListener {

void onLayoutChange(boolean changed, int left, int top, int right,

int bottom);

}

public interface OnScrollFinishedListener {

/**

* Callback method to be invoked when the scroll has completed.

*

* @param currentX

*            The current scroll position of the view

*/

void onScrollFinished(int currentX);

}

}

为什么要继承AdapterView, 大家可以去看看Android提供的ListView是怎么实现的,

public class ListView extends AbsListView

public abstract

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值