Skip to content

Load slideshow items on runtime causes slideshow have a bad visual behavior #60

Open
@Morteza-Rastgoo

Description

@Morteza-Rastgoo

Thanks for this great library.
I am loading item url and descriptions from server and on runtime add them as text sliders. and this is my code in asyncTask:

    public class InitializeSliderAsync extends AsyncTask<Object, Object, List<TextSliderView>> {
    private SliderLayout slider;
    private List<FeaturedItem> mItems;

    public void setItems(List<FeaturedItem> items) {
        mItems = items;
    }

    @Override
    protected List<TextSliderView> doInBackground(Object... params) {
        this.slider = (SliderLayout) params[0];
        List<TextSliderView> slides = new ArrayList<TextSliderView>();
        TextSliderView textSliderView;
        for (FeaturedItem item : mItems) {
            textSliderView = new TextSliderView(getActivity());
            // initialize a SliderLayout
            textSliderView.image(getString(R.string.server_address_http) + item.getImage())
                          .description(item.getLink())
                          .setScaleType(BaseSliderView.ScaleType.Fit)
                          .setOnSliderClickListener(new BaseSliderView.OnSliderClickListener() {
                                                        @Override
                                                        public void onSliderClick(BaseSliderView baseSliderView) {
                                                           // some method
                                                        }
                                                    }
                                                   );
            slides.add(textSliderView);
        }
        return slides;
    }

    @Override
    protected void onPostExecute(List<TextSliderView> slides) {
        setSliderLoading(true);
        mSlider.removeAllSliders();
        for (TextSliderView slide : slides) {
            mSlider.addSlider(slide);
        }

        mSlider.setPresetTransformer(SliderLayout.Transformer.Default);
        mSlider.setCustomIndicator(mPagerIndicator);
        mSlider.setDuration(4000);

    }
}

I load slider in a fragment:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_browse, container, false);
    this.mSlider = (SliderLayout) rootView.findViewById(R.id.slider);
}

 // Otto event for loading items from server.
@Subscribe
public void onItemsLoaded(FeaturedItemsLoadedEvent event) {
    mItems.clear();
    mItems.addAll(event.getAllFeaturedItems());
    initializeSlider();
}

private void initializeSlider() {
    setSliderLoading(true);
    InitializeSliderAsync initializeSliderAsync = new InitializeSliderAsync();
    initializeSliderAsync.setFeaturedItem(mItems);
    initializeSliderAsync.execute(mSlider);
}

and this is my layout file:

        <RelativeLayout
    android:id="@+id/slider_container"
    android:layout_width="fill_parent"
    android:layout_height="@dimen/browse_fragment_slideshow_height"
    android:layout_alignParentTop="true"
    android:gravity="center"
    android:orientation="vertical">

    <com.daimajia.slider.library.SliderLayout
        android:id="@+id/slider"
        android:layout_width="match_parent"
        android:layout_height="@dimen/browse_fragment_slideshow_height"
        android:layout_alignParentTop="true"
        custom:auto_cycle="true"/>

    <com.daimajia.slider.library.Indicators.PagerIndicator
        android:id="@+id/custom_indicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/slider"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="10dp"
        custom:selected_color="@color/ahangStyle_color"
        custom:unselected_color="@color/layout_background"/>
</RelativeLayout>

and I have two problems:

  1. Refreshing this list causes slider to have a bad visual when inserting new items in it.(you can try adding any items during runtime and see what i mean.) and this is not what user expects to see.
  2. when Autocycle is on, I get a lag in entire application UI when switching to new style and slide animation is not smooth.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions