问一下本人这个动态添加按钮的坐标哪里设置错了为什么会这样

Android 码拜 8年前 (2016-05-15) 1183次浏览
问一下本人这个动态添加按钮的坐标哪里设置错了为什么会这样
代码如下:

for(int i=0;i<stu_nums;++i)
        {
            Button button = new Button(this);
            //button.setText(stu_list.get(i).name);
            //button.setTextColor(Color.parseColor("#121212"));
            //button.setTextSize(20);
            button.setBackgroundColor(GetColor(stu_list.get(i).state));
            LinearLayout.LayoutParams lparam = new LinearLayout.LayoutParams(btn_width,btn_width);
            lparam.leftMargin =(i % 3 + 1) * 20 +   i % 3 * btn_width;
            lparam.topMargin = 20 + i / 3 * (10 + btn_width);
            layout.addView(button,lparam);
        }
解决方案

20

你的Layout 是LinearLayout 么?
换RelativeLayout 试试

10

貌似没什么问题,你调整下lparam.topMargin的值试试,可能是楼上说的你用的线性布局属性给的垂直方向造成的

10

引用:

貌似没什么问题,你调整下lparam.topMargin的值试试,可能是楼上说的你用的线性布局属性给的垂直方向造成的

LinearLayout.LayoutParams………………….


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明问一下本人这个动态添加按钮的坐标哪里设置错了为什么会这样
喜欢 (0)
[1034331897@qq.com]
分享 (0)