相对于父视图的滚动视图

时间:2013-02-06 11:50:29

标签: android

enter image description here

嗨大家好我的问题非常简单

我想在一行中添加图像,如flowlayout或GridLayout,如下图所示

在该布局上方,我想添加一个按钮,使其位于行之间。 当我滚动网格视图时,按钮图像也会与网格视图一起滚动。

任何人都可以向我提出一些可能的建议吗

1 个答案:

答案 0 :(得分:1)

如果它总是第四项 - 那一定没问题。

使用android:numColumns =“3”

强制使用GridView

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

这个想法是在第二行添加两个空白项目,在中间添加一个按钮。

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/

相关问题