加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

在java中拖动多个按钮视图

发布时间:2020-05-25 00:01:18 所属栏目:Java 来源:互联网
导读:我有一个应用程序,我需要移动堆栈的按钮(就像将一堆卡片的一部分从一堆移动到另一堆).我已经在xml布局中定义了所有按钮,并为所有人设置了触摸和拖动侦听器. 我可以单独拖放屏幕周围的任何按钮.但在某些情况下我需要做的是拖动堆叠在我同时点击的原始按钮顶部

我有一个应用程序,我需要移动堆栈的按钮(就像将一堆卡片的一部分从一堆移动到另一堆).我已经在xml布局中定义了所有按钮,并为所有人设置了触摸和拖动侦听器.
我可以单独拖放屏幕周围的任何按钮.但在某些情况下我需要做的是拖动堆叠在我同时点击的原始按钮顶部的其他按钮.
有没有办法“欺骗”或模拟按下另一个按钮(所以听众注册它)?
谢谢
***编辑于2015年9月8日
@覆盖
public boolean onTouch(View v,MotionEvent e){
// tosty(“mclicking:”mClicking);
int startpos = 0;
switch(e.getAction()& MotionEvent.ACTION_MASK){

case MotionEvent.ACTION_DOWN:

        isWastePile=false;

        get_selected_deck(v); // determines which of 7 decks or layouts in the tablau you have
                                // clicked
        FromDeck = selecteddeck;
        FromDeckCard = deckcard;
        FromDeckButton = deckbutton;
        // if (!mClicking) {
        mClicking = true;
        //String piecetag = (String) v.getTag();

        // // IDEA!!!/ ///
        /*
         * I wrote a function that finds all the ImageButtons below where
         * the user clicked,and set them all to invisible. I then created a
         * new Linear Layout within the Linear Layout that the user clicked (during the ACTION_DOWN event),* and passed that into the Drag Shadow builder during the ACTION_MOVE event.
         * 
         * Once into the ACTION_DROP portion,I simply referenced global
         * variables to figure out if the user dropped in one or multiple
         * ImageButtons,and dealt with them accordingly.
         */

        //if (!isWastePile) {
        //draglayout.setClipChildren(false);
        lltemp = new LinearLayout(this);
        lltemp.setOrientation(LinearLayout.VERTICAL);
        LinearLayout.LayoutParams llparams = new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

        llparams.setMargins(0,-52,0);
        lltemp.setLayoutParams(llparams);
        draglayout.addView(lltemp);


        for (int i = 0; i < deckstack_list[selecteddeck].size(); i++) {
            if (v == (draglayout.getChildAt(i))) {
                startpos = i;
                for (int o = i; o < deckstack_list[selecteddeck].size(); o++) {
                    // layout5.removeViewAt(o);
                    draglayout.getChildAt(o).setVisibility(View.GONE); // all
                                                                            // buttons
                                                                            // being
                    dragtempstack.push((Integer) deckstack_list[selecteddeck].get(o))   ;                                                   // dragged
                                                                            // to
                                                                            // invisible
                    // then recreate another linear layout within layout5
                    // and pass to dragshadow builder
                    // to do

                    // also set a GLOBAL variable with stack count (number
                    // of cards dragged)
                    lltemp.setClipChildren(false);
                    lltemp.addView(createtempButtons(o,startpos));


                }

            }
        }
        /

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读