2013-02-06 93 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/