(bwin娱乐平台下载地址) 关于动态添加view的位置问题
bwin娱乐下载
bwin娱乐下载
当前位置 : bwin娱乐下载 > bwin娱乐平台下载地址

(bwin娱乐平台下载地址) 关于动态添加view的位置问题

根据gridview的子项点击添加一个button在一个linearlayout中,并且这个button可以移动,但是每次添加之前添加的view的位置就会重置,设置layoutParams的margin又会出现不停的闪的情况

composeMainHoriView.setOnItemClickListenernew MyHorizontalScrollView.OnItemClickListener {
            @Override
            public void onClickView view, int pos {
                final Button button = new Buttoncontext;
                button.setBackgroundResourcedrableIdList.getpos;
                final LinearLayout.LayoutParams llp = new LinearLayout.LayoutParamsLinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT;
                button.setLayoutParamsllp;
                button.setOnTouchListenernew View.OnTouchListener {
                    @Override
                    public boolean onTouchView v, MotionEvent event {
                        int firstX = 0;
                        int firstY = 0;
                        switch event.getAction {
                            case MotionEvent.ACTION_DOWN:
                                firstX = int event.getX;
                                firstY = int event.getY;
                                break;
                            case MotionEvent.ACTION_MOVE:
                                int currentX = int event.getX - button.getWidth / 2;
                                int currentY = int event.getY - button.getHeight / 2;
                                int x = currentX - firstX;
                                int y = currentY - firstY;
                                button.offsetTopAndBottomy;
                                button.offsetLeftAndRightx;
                                break;
                            default:
                                break;
                        }
                        return true;
                    }
                };
                composeMainCenterFl.addViewbutton;

广告位

bwin娱乐下载