每行有机器人的GridView自己的航向 [英] Each row has its own heading in android gridview

查看:302
本文介绍了每行有机器人的GridView自己的航向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了Android GridView控件的应用程序。我的gridview的由10行和7列。其实这是一个彩色图表,以便在GridView的每个元素应该是不同的颜色。我已经创造了绘folder.The问题的因素是,我需要把标题上的每一行,而不是对每个元素。
假设我有一个像头那么我不得不把头上的row.This最左边元素的顶部标题就是我到底要:

我有什么实现这一目标呢?

 公共查看getView(INT位置,查看convertView,父母的ViewGroup){
    // TODO自动生成方法存根
    ViewHolder图。
    LayoutInflater充气= activity.getLayoutInflater();    如果(convertView == NULL)
    {
        鉴于=新ViewHolder();
        convertView = inflator.inflate(R.layout.gridview_row,NULL);        view.txtViewTitle =(TextView中)convertView.findViewById(R.id.textView1);
        view.imgViewFlag =(ImageView的)convertView.findViewById(R.id.imageView1);        convertView.setTag(视图);
    }
    其他
    {
        鉴于=(ViewHolder)convertView.getTag();
    }    view.txtViewTitle.setText(listCountry.get(位置));
    view.imgViewFlag.setImageResource(listFlag.get(位置));    返回convertView;
}


解决方案
而不是直接在适配器中使用可绘制的

,你可以尝试使用它有一个标题的TextView 和图像的ImageView 在它之下。

现在在适配器可在getview(),你可以设置绘制到的ImageView,并设置标题到位置0,7,14的元素......等等,为所有其他职位都有标题

编辑:(进一步说明)

在自定义布局,有头的知名度为

  @覆盖
公共查看getView(INT位置,查看convertView,父母的ViewGroup){
   如果(位置== 0 ||位置%7 == 0){
     //此处修改标题
     //设置能见度可见这里
   }
   其他
      //设置可见这里了 //此处添加图片视图}

I am developing an app with android gridview. My gridview consists of 10 rows and 7 columns. Actually this is a color chart so each element in the gridview should be of different color. I have created the elements in the drawable folder.The problem is that I need to put a heading on each row and not for each element. Suppose I have a heading like "head" then I have to put the "head" on the top of the left most element in the row.This is what i exactly want:

What do I have to do for achieving this ?

public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    ViewHolder view;
    LayoutInflater inflator = activity.getLayoutInflater();

    if(convertView==null)
    {
        view = new ViewHolder();
        convertView = inflator.inflate(R.layout.gridview_row, null);

        view.txtViewTitle = (TextView) convertView.findViewById(R.id.textView1);
        view.imgViewFlag = (ImageView) convertView.findViewById(R.id.imageView1);

        convertView.setTag(view);
    }
    else
    {
        view = (ViewHolder) convertView.getTag();
    }

    view.txtViewTitle.setText(listCountry.get(position));
    view.imgViewFlag.setImageResource(listFlag.get(position));

    return convertView;
}

解决方案

Instead of using drawables directly in your adapter, you could try using a custom layout which has a heading TextView and an image ImageView under it.

Now In the adpater, in the getview(), you could set the drawable to the ImageView and set the heading to the elements in positions 0,7,14... and so on and for all other positions have the heading Gone.

EDIT: (explaining further)

in your custom layout, have the visibility of header as Gone

@Override
public View getView(int position, View convertView, ViewGroup parent) {
   if(position==0 || position%7==0){
     // modify header here 
     // set visibility to visible here 
   }
   else
      // set visibility to gone here

 // add image view here

}

这篇关于每行有机器人的GridView自己的航向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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