如何应用点击监听器? [英] How To apply click listener?

查看:203
本文介绍了如何应用点击监听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用该页面卷曲提出申请正在使用此链接: -

I am making an application by using page curl for that am using this link:-

    https://github.com/harism/android_page_curl.

在使用bitmap.But我的要求,实现页面卷曲的链接是卷曲查看,对于我转换
       查看(LinearLayout中)为位图,并设置onclicklistener儿童来看,更多的澄清,请参阅
       附加的图像
       

In that link implementing page curl using bitmap.But My requirement is that curl to View ,for that I convert View(LinearLayout) into bitmap and set onclicklistener on child view, for more clarification please see attached image

我的code是为: -

My code is as:-

public static LinearLayout createProgrammeView(final Context context,
        int width, int height, String title, String time) {


    // Upper layout of screen
    LinearLayout objmainlayout = new LinearLayout(context);

    if (height >= 320) {
        objmainlayout.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT, (height -100)));
        Log.e("chectttttttttttlayout",""+(height-71));
    } else {
        objmainlayout.setLayoutParams(new LayoutParams(
                LayoutParams.FILL_PARENT, (height - 90)));
    }
    objmainlayout.setBackgroundColor(Color.WHITE);
    objmainlayout.setOrientation(LinearLayout.VERTICAL);
    objmainlayout.setPadding(10, 0, 10,0);


    for (int mindex = 0; mindex <3; mindex++)
    {
        RelativeLayout.LayoutParams objparams;
        // Layout Root View (RelativeLayout)

        RelativeLayout objrelativeinnerlayout = new RelativeLayout(context);
        if (height >= 320) 
        {
            objparams = new RelativeLayout.LayoutParams(width-20,
                    ((height - 71) / 3) - 10);
            Log.e("chectt33333tlayout",""+(((height - 71) / 3) - 10));
        } else {
            objparams = new RelativeLayout.LayoutParams(width,
                    ((height - 90) / 3) - 10);
        }
        //objparams.topMargin=10;
        objrelativeinnerlayout.setLayoutParams(objparams);
        // rlv.setBackgroundResource(R.drawable.sss);
        // rlv.setBackgroundResource(R.drawable.sss);


        ImageView objrow1img1 = new ImageView(context);
        if (height >= 320) {
            objrow1img1.setLayoutParams(new RelativeLayout.LayoutParams(
                    (width - 30) / 2,((height - 71) / 3) - 10));
        }
        objrow1img1.setScaleType(ScaleType.FIT_XY);

        RelativeLayout.LayoutParams objlp = (RelativeLayout.LayoutParams) objrow1img1.getLayoutParams();

        objlp.topMargin=10;
        objlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        objrow1img1.setId(1);
        objrow1img1.setBackgroundColor(Color.RED);

        if (mindex == 0) {
            objrow1img1.setImageResource(R.drawable.fblogin);
            objrow1img1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Toast.makeText(context,"onclick",Toast.LENGTH_LONG).show();
                    Log.e("check click","good");
                    //Intent objIntent = new Intent(context,
                            //FacebookAlbumList.class);
                    //objcoContext.startActivity(objIntent);
                }
            });
        }
        else {/*
            if (data != null
                    && data.size() > saveindex
                    && data.get(saveindex) != null
                    && data.get(saveindex).get(0) != null
                    && data.get(saveindex).get(0).getImagepath() != null) {
                objrow1img1.setVisibility(View.VISIBLE);
                System.gc();
                decodeBitMap(data.get(index).get(0).getImagepath(),
                        objrow1img1);
            } else {
                objrow1img1.setVisibility(View.INVISIBLE);
            }
        */}
        objrelativeinnerlayout.addView(objrow1img1);

        ImageView objrow1img2 = new ImageView(context);
        objrow1img2.setLayoutParams(new RelativeLayout.LayoutParams(
                (width - 30) / 2,((height - 71) / 3) - 10));
        objrow1img2.setScaleType(ScaleType.FIT_XY);
        objrow1img2.setBackgroundColor(Color.RED);

        RelativeLayout.LayoutParams objlrelativelayoutparam = (RelativeLayout.LayoutParams) objrow1img2
                .getLayoutParams();
        objlrelativelayoutparam.setMargins(10, 10, 0, 0);
        objlrelativelayoutparam.addRule(RelativeLayout.RIGHT_OF,1);

        objrelativeinnerlayout.addView(objrow1img2);

        objmainlayout.addView(objrelativeinnerlayout);

    }
    return objmainlayout;
}

public static Bitmap loadBitmapFromView(LinearLayout v) {
    v.measure(MeasureSpec.makeMeasureSpec(v.getLayoutParams().width,
            MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(
            v.getLayoutParams().height, MeasureSpec.EXACTLY));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());

    Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
            Bitmap.Config.RGB_565);
    Canvas c = new Canvas(b);
    v.draw(c);
    return b;
}

下面我把MyView的的code和转换入bitmap.Problem是,我怎样才能onclickListener上?
请任何人都建议我先谢谢了。

Here I put code of Myview and converting it into bitmap.Problem is that How I can get onclickListener on that? Please anyone suggest me thanks in advance.

推荐答案

我遇到了类似的问题,。得到它的工作我有一个父布局(contentContainer),其中包含2子视图:

I ran into a similar problem and. To get it working I have a parent layout (contentContainer) which contains 2 subviews:


  • 冰壶时被转换为位图的内容查看

  • CurlView(OpenGL的表面)

我只好一个onClickListener设置为父布局赶上事件和发送或不将它们发送到CurlView。当事件被发送到CurlView,所述CurlView被带到前(使用bringToFront()方法)。否则,内容视图被带到前面。

I had to set an onClickListener to the parent layout to catch the events and send or not send them to the CurlView. When the events are sent to the CurlView, the CurlView is brought to front (using bringToFront() method). Otherwise, the content view is brought to front.

要决定,如果事件被发送或不给CurlView我用,如果水龙头是页面卷曲区域(近似1/6的画面,两侧)内返回true的方法。另外我有一个姿态,规模探测器检测singleTap和长期preSS,这是我们需要的用户交互。当singleTap或长preSS被逮住,在现在的位置(X,Y)告诉我,当用户触动,所以我可以推出一些活动,展现出上下文菜单或什么的。

To decide if events are sent or not to the CurlView I use a method that returns true if the tap was within the page curl area (aprox. 1/6 of the screen, both sides). Additionally I have a gesture and scale detectors to detect singleTap and longPress, which is what we need for user interaction. When a singleTap or longPress is catched, the postion (x,y) tells me where the user touched so I can launch some activity, show a context menu or whatever.

一些示例code:

    contentContainer.setOnClickListener(null); // DO NOT REMOVE THIS, IT'S A WORKAROUND
    contentContainer.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            gestureDetector.onTouchEvent(event);
            mScaleDetector.onTouchEvent(event);

            int x = (int)event.getX();
            int y = (int)event.getY();

            boolean isMoving = event.getAction() == MotionEvent.ACTION_MOVE;
            boolean isTouchDown = event.getAction() == MotionEvent.ACTION_DOWN;
            boolean isTouchUp = event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL;
            boolean pageCurlArea = isPageCurlArea(x, y);

            boolean sendEventToCurlView = false;

            if (isTouchDown && pageCurlArea) {
                downInPageArea = true;
                sendEventToCurlView = true;
            } else if (downInPageArea && isMoving) {
                sendEventToCurlView = true;
            } else if (downInPageArea && isTouchUp) {
                downInPageArea = false;
                sendEventToCurlView = true;
            } else if (!downInPageArea && isMoving) {
                return false;
            }

            if (downInPageArea && isMoving && !curlViewIsOnTop) {
                bringCurlViewToFront();
            }

            if (sendEventToCurlView) {
                MotionEvent mEvent = MotionEvent.obtain(event);
                mCurlView.onTouch(v, mEvent);
            }

            return !sendEventToCurlView;
        }
    });

这是一项正在进行的工作,但因为我需要修改它不使用页面卷曲区,卷曲事件等事件(singleTap,长preSS ...),其区分我打算使用两个手势和规模探测器返回,如果事件被钓到并根据结果,继续发送所述事件到CurlView与否。这是必要的1/6页卷曲区域内执行抽头和长preSS的

It is a work in progress yet, because I need to modify it to not use "page curl area" to discriminate between "curl event" and other events (singleTap, longPress...), for which I plan to use both the gesture and scale detectors to return if an event was catched and depending on the result, continue sending the event to the CurlView or not. This is necessary to perform "taps" and "longPress" within the 1/6 page curl area.

希望它帮助。

这篇关于如何应用点击监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆