Android GridView使项目适合每个屏幕大小

Android GridView使项目适合每个屏幕大小,android,android-layout,gridview,Android,Android Layout,Gridview,我使用gridvew作为布局来填充我的项目,圈出按钮,但我在安装大网格(11 x 11)时遇到了问题。当我使用更大的屏幕时,它适合但中途停止?这是因为我在roundbutton.xml中放了szie吗?在我的手机较小的屏幕上,它确实适合并延伸到屏幕的两端。我需要适合屏幕,11 x 11的大小是多少 网格视图布局 <?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="http://schemas.andro

我使用gridvew作为布局来填充我的项目,圈出按钮,但我在安装大网格(11 x 11)时遇到了问题。当我使用更大的屏幕时,它适合但中途停止?这是因为我在roundbutton.xml中放了szie吗?在我的手机较小的屏幕上,它确实适合并延伸到屏幕的两端。我需要适合屏幕,11 x 11的大小是多少

网格视图布局

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridView1"
    android:numColumns="11"
    android:gravity="center"
    android:stretchMode="columnWidth"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</GridView>
adapter.java

@Override
public View getView(final int position, View convertView, final ViewGroup parent)
    {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

为此,您必须计算设备运行时的宽度和高度

int width = devicewidth/11 ;
int height =deviceheight/11 ;
使用此参数必须传入
GridView的适配器

android.widget.AbsListView.LayoutParams parms = new android.widget.AbsListView.LayoutParams(width , height);

用于调整其单元格的大小。

这将转到何处?在主活动中还是在适配器中?请参阅上面的附加代码。如何获取devicewidth和deviceheight?没有真正按照你的建议去做,你有消息来源吗?或者如果可能的话,举个例子?谢谢我假设您指的是主活动中onCreate中的运行时,并将这些值公开和静态,以便可以与适配器共享它们?能够计算得到维度,但我不会将parms传递给gridview。我怎么知道的?@MAXGEN你的主布局有gridview吗?还有两个活动,其中一个称为适配器,但不确定为什么两个活动的名称相同?功能与禁用视图只有细微的区别?将自定义适配器和按钮作为项目而不是图像会有问题吗?您是否建议不要在适配器内部使用onClick适配器,而是像使用主活动一样使用它?谢谢
@Override
public View getView(final int position, View convertView, final ViewGroup parent)
    {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int width = devicewidth/11 ;
int height =deviceheight/11 ;
android.widget.AbsListView.LayoutParams parms = new android.widget.AbsListView.LayoutParams(width , height);