Viewpager Fragement内部的Android Listview-无滚动

Viewpager Fragement内部的Android Listview-无滚动,第1张

概述我试图在Viewpager中创建一个ListView.ViewPager正在使用Fragements.所以ListView在Fragement内部.我的Listview没有滚动,尽管在Listview中onitmclicked和ontouch被调用.我的密码<RelativeLayoutxmlns:android="http://schemas.android.com/apkes/android"xmlns:tools="htt

我试图在VIEwpager中创建一个ListVIEw.
VIEwPager正在使用Fragements.
所以ListVIEw在Fragement内部.
我的ListvIEw没有滚动,尽管在ListvIEw中onitmclicked和ontouch被调用.

我的密码

<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools"xmlns:app="http://schemas.androID.com/apk/res-auto"xmlns:app1="http://schemas.androID.com/apk/res/com.bookthefIEld.user"androID:layout_wIDth="match_parent"androID:layout_height="match_parent" ><androID.support.v4.vIEw.VIEwPager    androID:ID="@+ID/pager"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:layout_below="@+ID/tabHost"    androID:focusableIntouchMode="false" /><utilitIEs.PagerSlIDingTabStrip    androID:ID="@+ID/tabs"    androID:layout_wIDth="match_parent"    androID:layout_height="48dip"    androID:layout_alignParentBottom="true"    androID:layout_alignParentleft="true"    androID:background="@color/white"    app1:pstsIndicatorcolor="@color/available"    app1:pstsShouldExpand="true" ></utilitIEs.PagerSlIDingTabStrip></relativeLayout><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:background="#d8d7dd" ><ListVIEw    androID:ID="@+ID/lvalltourney"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:layout_alignParentleft="true"    androID:layout_alignParenttop="true"    androID:layout_marginBottom="10dp"    androID:layout_marginleft="10dp"    androID:layout_marginRight="10dp"    androID:layout_margintop="10dp"    androID:divIDer="#d8d7dd"    androID:divIDerHeight="10dp" ></ListVIEw></relativeLayout>  lvalltourney.setontouchListener(new VIEw.OntouchListener() {        @OverrIDe        public boolean ontouch(VIEw v, MotionEvent event) {            lvalltourney.getParent().requestdisallowIntercepttouchEvent(                    true);            int action = event.getActionMasked();            switch (action) {            case MotionEvent.ACTION_UP:                lvalltourney.getParent()                        .requestdisallowIntercepttouchEvent(false);                break;            }            return false;        }    });

适配器代码

class tourneyadapter extends BaseAdapter {    private Context mContext;    private final ArrayList<tourney> tourneyList;    public tourneyadapter(Context c, ArrayList<tourney> tourneyList) {        mContext = c;        this.tourneyList = tourneyList;    }    @OverrIDe    public int getCount() {        // Todo auto-generated method stub        return tourneyList.size();    }    @OverrIDe    public Object getItem(int position) {        // Todo auto-generated method stub        return null;    }    @OverrIDe    public long getItemID(int position) {        // Todo auto-generated method stub        return 0;    }    @OverrIDe    public VIEw getVIEw(final int position, VIEw convertVIEw,            VIEwGroup parent) {        // Todo auto-generated method stub        VIEw grID; //        LayoutInflater inflater = (LayoutInflater) mContext                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);        if (convertVIEw == null) {            grID = new VIEw(mContext);            grID = inflater.inflate(R.layout.tourneyListingitem, null);        } else {            grID = (VIEw) convertVIEw;        }        final tourney temp = tourneyList.get(position);        TextVIEw tvtourneyname = (TextVIEw) grID                .findVIEwByID(R.ID.tvtourneyname);        tvtourneyname.setText(temp.getname());        TextVIEw tvlocationname = (TextVIEw) grID                .findVIEwByID(R.ID.tvlocationtourney);        tvlocationname.setText(temp.getAddress());        TextVIEw tvdatetourney = (TextVIEw) grID                .findVIEwByID(R.ID.tvdatetourney);        tvdatetourney.setText(temp.getDate());        try {            TextVIEw tvcost = (TextVIEw) grID                    .findVIEwByID(R.ID.tventeryfee);            tvcost.setText(temp.getEntryfee() + " ");            ImageVIEw imagesport = (ImageVIEw) grID                    .findVIEwByID(R.ID.imagesport);            imagesport.setimageResource(temp.getDrawable());        } catch (Exception e1) {            // Todo auto-generated catch block            e1.printstacktrace();        }        return grID;    }}

更新:1

我扩展了VIEwpager并在xml和javacode中使用了它

public class MyVIEwPager extends VIEwPager {private GestureDetector mGestureDetector;VIEw.OntouchListener mGestureListener;public MyVIEwPager(Context context, AttributeSet attrs) {    super(context, attrs);    mGestureDetector = new GestureDetector(context, new YScrollDetector());    setFadingEdgeLength(0);}@OverrIDepublic boolean onIntercepttouchEvent(MotionEvent ev) {    return super.onIntercepttouchEvent(ev)            && mGestureDetector.ontouchEvent(ev);}// Return false if we're scrolling in the x directionclass YScrollDetector extends SimpleOnGestureListener {    @OverrIDe    public boolean onScroll(MotionEvent e1, MotionEvent e2,            float distanceX, float distanceY) {        return Math.abs(distanceY) > Math.abs(distanceX);    }}}

解决方法:

将您的ListVIEw的高度设置为wrap_content

androID:layout_height = "wrap_content"

固定高度时,它不会滚动.

编辑

同时删除此部分:

lvalltourney.setontouchListener(new VIEw.OntouchListener() {    @OverrIDe    public boolean ontouch(VIEw v, MotionEvent event) {        lvalltourney.getParent().requestdisallowIntercepttouchEvent(                true);        int action = event.getActionMasked();        switch (action) {        case MotionEvent.ACTION_UP:            lvalltourney.getParent()                    .requestdisallowIntercepttouchEvent(false);            break;        }        return false;    }});
总结

以上是内存溢出为你收集整理的Viewpager Fragement内部的Android Listview-无滚动全部内容,希望文章能够帮你解决Viewpager Fragement内部的Android Listview-无滚动所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存