GridLayout - 填充屏幕

时间:2013-12-03 19:49:10

标签: android layout

我是Android编程的新手(今天开始:P),我的问题是:

我正在为此活动使用GridLayout,我在此活动的onCreate()方法中添加了按钮。如何区分布局以水平和垂直填充整个屏幕,相应地调整单元格大小? (每个单元格应具有相同的宽度/高度)

这就是我现在所拥有的。如果您需要代码,请告诉我,我不太确定要发布什么。

Fail

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fuckthis"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="7"
    android:orientation="horizontal"
    android:rowCount="5" >
</GridLayout>

添加按钮:

for(int i=0;i<cards.length;i++) {
    cards[i] = new MemoryCard(this, i);
    GridLayout.Spec rowspecs = GridLayout.spec(i/7, 1); 
    GridLayout.Spec colspecs = GridLayout.spec(i%7, 1);
    GridLayout.LayoutParams gridLayoutParam = new GridLayout.LayoutParams(rowspecs, colspecs);
    cards[i].setLayoutParams(gridLayoutParam);
    gl.addView(cards[i], gridLayoutParam);
}

0 个答案:

没有答案