android – 像PInterest这样的布局

前端之家收集整理的这篇文章主要介绍了android – 像PInterest这样的布局前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在我的代码中创建像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);
那么第二个param convertView我想要使用RecycleBin的AbsListView类
我怎么能这样做?

解决方法

看看Umano团队的MultiItemRowListAdapter: https://github.com/umano/MultiItemRowListAdapter/blob/master/README.md
原文链接:https://www.f2er.com/android/314866.html

猜你在找的Android相关文章