2013-02-06 96 views
0

enter image description here滚动视图相对于父视图

嗨,大家好我的问题很简单

我要像一个的FlowLayout或网格布局的行添加图片,你可以在图片见下文

在布局之上,我想添加一个按钮,使它在行之间。 当我滚动我的网格视图时,按钮图像也滚动分别与gridview。

任何一个可以建议我一些想法,它如何能够

+0

使按键总是第一个*可见*行和第二之间可见? – Oritm

+0

yes按钮始终可见 – Bora

回答

1

如果它总是一个第四个项目 - 比必须是没有问题的。

Impelment与Android一个GridView:为numColumns =“3”

在适配器中实现三种视图类型

的想法是在第二排和一个按钮中间添加两个空白的项目。

private static final int TYPE_NORMAL = 0; 
private static final int TYPE_BLANK = 1; 
private static final int TYPE_BUTTON = 2; 


@Override 
public int getViewTypeCount() { 
    return 3; 
} 

@Override 
public int getCount() { 
    return yourdata.size() + 3; 
} 

// return your real data by skipping row with the button 
@Override 
public Object getItem(int position) { 
    if (position > 3) { 
     position += 3; 
    } 
    return yourdata.get(position); 
} 

// return your real data ID by skipping row with the button The button probably should catch it's own onClickListemer 
@Override 
public long getItemId(int position) { 
    if (position > 3) { 
     position += 3; 
    } 
    return yourdata.get(position).getId(); 
} 


@Override 
public int getItemViewType(int position) { 
    switch(position) { 
     case 4: 
     case 6: 
      return TYPE_BLANK; 

     case 5: 
      return TYPE_BUTTON; 

     default: 
      return TYPE_NORMAL; 
    } 
} 

// only your items should be clickable 
@Override 
public boolean isEnabled(int position) { 
    return position < 4 && position > 6; 
} 

// nope, only your specific data items are enabled. 
@Override 
public boolean areAllItemsEnabled() { 
    return false; 
} 

在yout getView方法中,只需检查项目视图类型并将适当的视图充气。 实现多种项目类型的适配器的详细信息请参见例的ListView的第头部等

How to generate a ListView with headers above some sections?

http://w2davids.wordpress.com/android-sectioned-headers-in-listviews/