查看填补所有可用空间 [英] View fills all the available space

查看:192
本文介绍了查看填补所有可用空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用网​​格布局编程。

下面是我的code:

  GridLayout的P =新的网格布局(本);
    p.setRowCount(20);
    p.setColumnCount(20);
    查看C =新的视图(本);
    c.setBackgroundColor(this.getResources()的getColor(R.color.darkbluetheme));
    规格specusata = android.support.v7.widget.GridLayout.spec(1,2);
    规格specusata2 = android.support.v7.widget.GridLayout.spec(1,2);
    p.addView(C,新的LayoutParams(specusata,specusata2));
    的setContentView(P);

下面是结果我得到:

虽然我期待这样的事情:

请我究竟做错了什么???

谢谢!

编辑编辑修改

这是即使我设置视图的的LayoutParams到WRAP_CONTENT:

  GridLayout的P =新的网格布局(本);
    p.setRowCount(20);
    p.setColumnCount(20);
    查看C =新景(DayActivity.this);
    c.setBackgroundColor(this.getResources()的getColor(R.color.darkbluetheme));
    规格specusata = android.support.v7.widget.GridLayout.spec(1);
    规格specusata2 = android.support.v7.widget.GridLayout.spec(1);
    c.setLayoutParams(新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
    p.addView(C,新android.support.v7.widget.GridLayout.LayoutParams(specusata,specusata2));
    的setContentView(P);


解决方案

恕我直言:你的其他行和列是空的,从而零宽度。你的空间的其余部分充满了单细胞,并采取一切空间。

尝试增加其他颜色更多孩子的意见,然后你就会明白发生了什么。

I am trying to use GridLayout programmatically.

Here is my code:

    GridLayout p = new GridLayout(this);
    p.setRowCount(20);
    p.setColumnCount(20);
    View c = new View(this);
    c.setBackgroundColor(this.getResources().getColor(R.color.darkbluetheme));
    Spec specusata = android.support.v7.widget.GridLayout.spec(1,2);
    Spec specusata2 = android.support.v7.widget.GridLayout.spec(1,2);
    p.addView(c,new LayoutParams(specusata,specusata2));
    setContentView(p);

Here is the result I get:

While i was expecting something like this:

Please what am I doing wrong???

Thanks !!!

EDIT EDIT EDIT

This happens even if i set the LayoutParams of the View to WRAP_CONTENT:

    GridLayout p = new GridLayout(this);
    p.setRowCount(20);
    p.setColumnCount(20);
    View c = new View(DayActivity.this);
    c.setBackgroundColor(this.getResources().getColor(R.color.darkbluetheme));
    Spec specusata = android.support.v7.widget.GridLayout.spec(1);
    Spec specusata2 = android.support.v7.widget.GridLayout.spec(1);
    c.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    p.addView(c,new android.support.v7.widget.GridLayout.LayoutParams(specusata,specusata2));
    setContentView(p);

解决方案

IMHO: Your other rows and columns are empty, and thus zero width. The rest of your space is filled with that single cell, and takes all space.

Try adding more child views with other colors, and then you will understand what happens.

这篇关于查看填补所有可用空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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