android – ListView中的Horizo​​ntalScrollView

android – ListView中的Horizo​​ntalScrollView,第1张

概述我正在尝试在ListView中创建一个水平滚动视图.我有ListView工作,但将数据放入horizo​​ntalscrollview(HSV)并不适合我.请指教! (我编写了listview,经过测试,现在尝试添加horizo​​ntalscrollview) HSV将适用于每个列表项目. 所以基本上我的逻辑是关于我如何接近这个:我有我的listview适配器,我决定将HSV放在适配器中,以便循 我正在尝试在ListVIEw中创建一个水平滚动视图.我有ListVIEw工作,但将数据放入horizo​​ntalscrollvIEw(HSV)并不适合我.请指教! (我编写了ListvIEw,经过测试,现在尝试添加horizo​​ntalscrollvIEw)

HSV将适用于每个列表项目.

所以基本上我的逻辑是关于我如何接近这个:我有我的ListvIEw适配器,我决定将HSV放在适配器中,以便循环遍历每个ListItem并在其中放置一个HSV.

我的Xml外观如下:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:baselineAligned="false"    androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent">    <linearLayout    androID:orIEntation="vertical"    androID:layout_wIDth="0dip" androID:layout_weight="1"    androID:layout_height="fill_parent">        <TextVIEw        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:ID="@+ID/txtProjectname" />        <TextVIEw        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:ID="@+ID/txtProjectDescription" />        <horizontalscrollview            androID:layout_wIDth="wrap_content"            androID:layout_height="match_parent" >            <linearLayout                 androID:ID="@+ID/projectTasks"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:orIEntation="horizontal">                <TextVIEw                 androID:layout_wIDth="fill_parent"                androID:layout_height="wrap_content"                androID:ID="@+ID/txtProjectTasks" />            </linearLayout>        </horizontalscrollview>    </linearLayout></linearLayout>

然后我创建了一个自定义适配器来运行所有项目.

public class Projectlistadapter extends ArrayAdapter<Projects> {int resource;String response;Context context;ArrayList<Tasks> taskArray = null;// Initialize adapterpublic Projectlistadapter(Context context,int resource,List<Projects> items) {    super(context,resource,items);    this.resource = resource;}@OverrIDepublic VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) {    linearLayout projectVIEw;    // Get the current project object    Projects project = getItem(position);    //    // Inflate the vIEw    if (convertVIEw == null) {        projectVIEw = new linearLayout(getContext());        String inflater = Context.LAYOUT_INFLATER_SERVICE;        LayoutInflater vi;        vi = (LayoutInflater) getContext().getSystemService(inflater);        vi.inflate(resource,projectVIEw,true);    } else {        projectVIEw = (linearLayout) convertVIEw;    }    TextVIEw PROJECT_name = (TextVIEw) projectVIEw            .findVIEwByID(R.ID.txtProjectname);    TextVIEw PROJECT_DESCRIPTION = (TextVIEw) projectVIEw            .findVIEwByID(R.ID.txtProjectDescription);    PROJECT_name.setText(project.getname());    PROJECT_DESCRIPTION.setText(project.getDESCRIPTION());    taskArray = new ArrayList<Tasks>();    taskArray = (ArrayList<Tasks>) project.getTasks();    for (Tasks tasks : taskArray) {        horizontalscrollview TASKS = (horizontalscrollview) projectVIEw                .findVIEwByID(R.ID.projectTasks);        linearLayout taskLayout = (linearLayout) projectVIEw                .findVIEwByID(R.ID.projectTasks);        TextVIEw taskTxt = (TextVIEw) projectVIEw                .findVIEwByID(R.ID.txtProjectTasks);        taskTxt.setText(tasks.getTASK_ID());        taskLayout.addVIEw(taskTxt);    }    return projectVIEw;}

}

最后一段代码是适配器循环生成HSV的地方,但有些东西不能正常工作,请帮忙!

解决方法 请按照以下链接在ListVIEw中获得HSV:
http://www.dev-smart.com/archives/34

要么

@OverrIDepublic boolean ontouchEvent(MotionEvent event) {    boolean handled = mGesture.ontouchEvent(event);    return handled;}Then,add the following code which will decIDe to steal the event from the item children and give it to our ontouchEvent,or let it be handled by them.@OverrIDepublic boolean onIntercepttouchEvent(MotionEvent ev) {    switch( ev.getActionMasked() ){        case MotionEvent.ACTION_DOWN:             mInitialX = ev.getX();             mInitialY = ev.getY();                          return false;        case MotionEvent.ACTION_MOVE:             float deltaX = Math.abs(ev.getX() - mInitialX);             float deltaY = Math.abs(ev.getY() - mInitialY);             return ( deltaX > 5 || deltaY > 5 );        default:             return super.onIntercepttouchEvent(ev);    }}Finally,don't forget to declare the variables in your class:private float mInitialX;private float mInitialY;

资料来源:Horizontal ListView in Android?

总结

以上是内存溢出为你收集整理的android – ListView中的Horizo​​ntalScrollView全部内容,希望文章能够帮你解决android – ListView中的Horizo​​ntalScrollView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1124755.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存