3

I am looking for any library that help me to make a FlowLayout with adapter, like GridView, but i want to arrange elements in flow! What do you think, what is the best way to do that (FreeFlow)? I have created a StickyListHeadersListView with adapter:

   @Override
public View getView(int position,  View convertView, final ViewGroup parent) {
    FiltersChildViewHolder holder;
    if (convertView == null) {
        final View[] temp = new View[1];
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
             temp[0] = mInflater.inflate(R.layout.item_filters_layout, parent, false);
            }
        });
      convertView = temp[0];

        holder = new FiltersChildViewHolder();
        holder.flFilters_IFL = (FlowLayout) convertView.findViewById(R.id.flFilters_IFL);

        convertView.setTag(holder);
    } else {
        holder = (FiltersChildViewHolder) convertView.getTag();
    }


    ArrayList<FilterModel> filterModels = getFiltersForCategory(position);

    FilterLayoutAdapter adapter = new FilterLayoutAdapter(mActivity, filterModels);
    adapter.setOnFiltersChangedListener(mFiltersChangedListener);
    adapter.setIsDefault(isDefault);
    holder.flFilters_IFL.setAdapter(adapter);

    return convertView;
}

This is the getView() method in my adapter! Every list item is a FlowLayout, and the FilterLayoutAdapter will add views to this FlowLayout, this works for me, in this way the elements are arranged in flow, but the ListView is very freezy when I scroll to the next list item, because all childView are inflated immediatelly in FlowLayout and thera are 100 childView!

rMozes
  • 201
  • 3
  • 9

2 Answers2

1

Hello here is example using custom Library which acts like List GitHubLibrary TagLayout

  • Sample Code:-

mFlowLayout.setAdapter(new TagAdapter<String>(mVals) { @Override public View getView(FlowLayout parent, int position, String s) { TextView tv = (TextView) mInflater.inflate(R.layout.tv, mFlowLayout, false); tv.setText(s); return tv; } });

Using below code you can pre set selection you wanted:-

mAdapter.setSelectedList(1,3,5,7,8,9);

Will show result like below:-

enter image description here

Hardy
  • 2,576
  • 1
  • 23
  • 45
0

Use this code of section at the end of getView method before return view; line.

Animation animationY = new TranslateAnimation(0, 0,
                        parent.getHeight() / 4, 0);
                animationY.setDuration(1000);
                view.startAnimation(animationY);

where parent will be

public View getView(final int position, View convertView,
                ViewGroup parent)
Tushar Pandey
  • 4,557
  • 4
  • 33
  • 50
  • I don't understand, how it will solve my problem! My problem is that, every list item is a FlowLayout, every FlowLayout will have min 30 childs and when I inflate them, they are inflated immediatelly and this blocks the main thread, because i used ListView.I think that would work with GridView, but GridView does not arrange elements in flow! – rMozes Dec 18 '14 at 13:11
  • FlowLayout is a custom ViewGroup, it arranges elements in flow like FlowLayout in Java! For example : https://github.com/blazsolar/FlowLayout – rMozes Dec 18 '14 at 13:58