Android的GridView的项目行高度最大值 [英] android gridviews row height max of item

查看:505
本文介绍了Android的GridView的项目行高度最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的GridView。它的元素具有不同的高度。例如在一排有一小元件和一个更大的,下一行就会对准较小元件和更大的元件的一部分是在第二排下。如何设置GridView控件的每一行的高度是行最大的元素??

的高度

我的GridView

 < GridView中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
                机器人:ID =@ + ID / new_small_list
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =WRAP_CONTENT
                机器人:为numColumns =2
                机器人:verticalSpacing =3DP
                机器人:horizo​​ntalSpacing =3DP
                机器人:stretchMode =columnWidth中
                机器人:重力=中心
                机器人:cacheColorHint =@机器人:彩色/透明
            />
 

解决方案

有关设置单元格的高度,在GridViewAdapter当你写,例如:

  @覆盖
公共查看getView(INT位置,查看convertView,ViewGroup中父){

        如果(convertView == NULL){

            LayoutInflater cellLayout =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = cellLayout.inflate(R.layout.gridcell_layout,NULL);
        }

        TextView的cell_title =(TextView中)convertView.findViewById(R.id.gridview_cell_text);
        ImageView的cell_icon =(ImageView的)convertView.findViewById(R.id.griview_cell_image);
        ....
 

刚刚替补这一行:

  convertView = cellLayout.inflate(R.layout.gridcell_layout,NULL);
 

通过这样的:

  convertView = cellLayout.inflate(R.layout.gridcell_layout,GridView控件,FALSE);
 

通过这种方式,设置家长参考的膨胀,宽,高约电池将设置! 在这里你可以找到原因:

布局问题按钮保证金

i have simple gridview. it's elements have different height. for example in row there are one small element and one bigger, next row will align to smaller element and a part of bigger element is under the second row. how can i set the height of each row of gridview to be the height of the biggest element in row??

my gridview

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
                android:id="@+id/new_small_list"
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:numColumns="2"
                android:verticalSpacing="3dp"
                android:horizontalSpacing="3dp"
                android:stretchMode="columnWidth"
                android:gravity="center"
                android:cacheColorHint="@android:color/transparent"
            />

解决方案

For setting cell height, in GridViewAdapter when you write, for example:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

        if(convertView == null){

            LayoutInflater cellLayout = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);             
            convertView = cellLayout.inflate(R.layout.gridcell_layout, null);
        }

        TextView cell_title = (TextView) convertView.findViewById(R.id.gridview_cell_text);         
        ImageView cell_icon = (ImageView) convertView.findViewById(R.id.griview_cell_image);
        ....

Just substitute this line:

convertView = cellLayout.inflate(R.layout.gridcell_layout, null);

With this:

convertView = cellLayout.inflate(R.layout.gridcell_layout, gridView, false);

By this way, setting parent reference in "inflate", Width and Height about cell will set! Here you can find why:

Layout problem with button margin

这篇关于Android的GridView的项目行高度最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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