像PInterest这样的布局

时间:2012-03-26 03:54:41

标签: android

我想在我的代码中创建像 pinterest 这样的自定义视图,我在scrollview中使用scrollView和3 linearlayout 我自定义我的视图名称waterfallView这里是代码:

public class WaterfallView extends LinearLayout {

private ListAdapter m_Adapter;
private OnClickListener onClickListener = null;
private LinearLayout m_Line1;
private LinearLayout m_Line2;
private LinearLayout m_Line3;

public WaterfallView(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    InitLine();
}

public WaterfallView(Context context, AttributeSet attrs) {
    super(context, attrs);
    InitLine();
}

private void InitLine() {

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    lp.weight = 1;

    // line2
    m_Line1 = new LinearLayout(this.getContext());
    m_Line1.setOrientation(VERTICAL);
    m_Line1.setLayoutParams(lp);

    // line2
    m_Line2 = new LinearLayout(this.getContext());
    m_Line2.setOrientation(VERTICAL);
    m_Line2.setLayoutParams(lp);

    // line3
    m_Line3 = new LinearLayout(this.getContext());
    m_Line3.setOrientation(VERTICAL);
    m_Line3.setLayoutParams(lp);

    addView(m_Line1);
    addView(m_Line2);
    addView(m_Line3);
}

public ListAdapter getAdapter() {
    return m_Adapter;
}

private void BindLayout() {
    int count = m_Adapter.getCount();
    for (int i = 0; i < count; i++) {
        View v = m_Adapter.getView(i, null, null);
        v.setOnClickListener(this.onClickListener);
        if (i == 0 || i % 3 == 0)
            m_Line1.addView(v);

        if (i == 1 || i % 3 == 1)
            m_Line2.addView(v);

        if (i == 2 || i % 3 == 2)
            m_Line3.addView(v);
    }
    Log.v("countTAG", "" + count);
}

private void AddItem(){

}

public void setAdapter(ListAdapter adapter) {
    this.m_Adapter = adapter;
    BindLayout();
}

public OnClickListener getOnclickListner() {
    return onClickListener;
}

public void setOnclickLinstener(OnClickListener onClickListener) {
    this.onClickListener = onClickListener;
    }
}

在BindLayout函数中有m_Adapter.getView(i, null, null); 那么第二个param convertView我想要使用RecycleBin的AbsListView类 我怎么能这样做?

Pinterest 3 column layout

1 个答案:

答案 0 :(得分:0)

看一下Umano团队的MultiItemRowListAdapter:https://github.com/umano/MultiItemRowListAdapter/blob/master/README.md